about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-11-23 15:49:47 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-12-15 10:20:41 -0800
commit5076d9636b258c7f9d2485b9d19738b3602d8d9c (patch)
tree798c8057c41b168caf243efbd488f27d23667d03
parentcc4b1029669dcf58b2faee74656858c1be923142 (diff)
downloadmu-5076d9636b258c7f9d2485b9d19738b3602d8d9c.tar.gz
start working on checking address lifetime
First some baseline tests that should never trigger warnings.
-rw-r--r--061abandon_checks.cc126
1 files changed, 126 insertions, 0 deletions
diff --git a/061abandon_checks.cc b/061abandon_checks.cc
new file mode 100644
index 00000000..ae8ab75d
--- /dev/null
+++ b/061abandon_checks.cc
@@ -0,0 +1,126 @@
+:(scenarios transform)  // many of the tests below are *extremely* unsafe
+:(scenario abandon_in_same_recipe_as_new)
+recipe test [
+  x:address:number <- new number:type
+  abandon x
+]
+# no warnings
+
+:(scenario abandon_in_separate_recipe_from_new)
+recipe test [
+  x:address:number <- test-new
+  test-abandon x
+]
+recipe test-new -> result:address:number [
+  result <- new number:type
+]
+recipe test-abandon x:address:number [
+  load-ingredients
+  abandon x
+]
+# no warnings
+
+:(scenario define_after_abandon_in_same_recipe_as_new)
+recipe test [
+  x:address:number <- new number:type
+  abandon x
+  x <- new number:type
+  reply x
+]
+# no warnings
+
+:(scenario define_after_abandon_in_separate_recipe_from_new)
+recipe test [
+  x:address:number <- test-new
+  test-abandon x
+  x <- test-new
+  reply x
+]
+recipe test-new -> result:address:number [
+  result <- new number:type
+]
+recipe test-abandon x:address:number [
+  load-ingredients
+  abandon x
+]
+# no warnings
+
+:(scenario abandon_inside_loop_initializing_variable)
+recipe test [
+  {
+    x:address:number <- new number:type
+    abandon x
+    loop
+  }
+]
+# no warnings
+
+:(scenario abandon_inside_loop_initializing_variable_2)
+recipe test [
+  {
+    x:address:number <- test-new
+    test-abandon x
+    loop
+  }
+]
+recipe test-new -> result:address:number [
+  result <- new number:type
+]
+recipe test-abandon x:address:number [
+  load-ingredients
+  abandon x
+]
+# no warnings
+
+:(scenario abandon_inside_loop_initializing_variable_3)
+recipe test [
+  {
+    x:address:number <- test-new
+    test-abandon x
+    x:address:number <- test-new  # modify x to a new value
+    y:address:number <- copy x  # use x after reinitialization
+    loop
+  }
+]
+recipe test-new -> result:address:number [
+  result <- new number:type
+]
+recipe test-abandon x:address:number [
+  load-ingredients
+  abandon x
+]
+# no warnings
+
+:(scenario abandon_inside_loop_initializing_variable_4)
+container test-list [
+  value:number
+  next:address:test-list
+]
+recipe test-cleanup x:address:test-list [
+  load-ingredients
+  {
+    next:address:test-list <- test-next x
+    test-abandon x
+    x <- copy next
+    loop
+  }
+]
+recipe test-next x:address:test-list -> result:address:test-list/contained-in:x [
+  load-ingredients
+  result <- get *x, next:offset
+]
+recipe test-abandon x:address:test-list [
+  load-ingredients
+  abandon x
+]
+# no warnings
+
+:(scenario abandon_non_unique_address_after_define)
+recipe test [
+  x:address:number <- new number:type
+  y:address:number <- copy x
+  abandon x
+  y:address:number <- new number:type  # overwrite alias
+  z:address:number <- copy y
+]
+# no warnings