about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-05-26 15:48:35 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-05-26 15:48:35 -0700
commitafa42503cdae82c535208d51bec8d4f9a920f6f0 (patch)
tree2db25e3ccdbd40262ecd9e7767bbfa5bbe5f7d91
parentc8a58cdc8cc3353de3a42a9f53e5c4759ef9701a (diff)
downloadmu-afa42503cdae82c535208d51bec8d4f9a920f6f0.tar.gz
1474 - another warning
-rw-r--r--002test.cc1
-rw-r--r--030container.cc17
-rw-r--r--032array.cc13
-rw-r--r--034exclusive_container.cc9
-rw-r--r--037call_reply.cc2
-rw-r--r--041name.cc22
6 files changed, 47 insertions, 17 deletions
diff --git a/002test.cc b/002test.cc
index 159932d6..a35f95bf 100644
--- a/002test.cc
+++ b/002test.cc
@@ -54,6 +54,7 @@ if (Run_tests) {
   time_t t; time(&t);
   cerr << "C tests: " << ctime(&t);
   for (size_t i=0; i < sizeof(Tests)/sizeof(Tests[0]); ++i) {
+//?     cerr << i << '\n'; //? 1
     run_test(i);
   }
   // End Tests
diff --git a/030container.cc b/030container.cc
index fbb0f87c..2bc540bb 100644
--- a/030container.cc
+++ b/030container.cc
@@ -14,11 +14,14 @@ Type[point].elements.push_back(i);
 //: Containers can be copied around with a single instruction just like
 //: numbers, no matter how large they are.
 
+//: Tests in this layer often explicitly setup memory before reading it as a
+//: container. Don't do this in general. I'm tagging exceptions with /raw to
+//: avoid warnings.
 :(scenario copy_multiple_locations)
 recipe main [
   1:number <- copy 34:literal
   2:number <- copy 35:literal
-  3:point <- copy 1:point
+  3:point <- copy 1:point/raw  # unsafe
 ]
 +mem: storing 34 in location 3
 +mem: storing 35 in location 4
@@ -42,7 +45,7 @@ recipe main [
   12:number <- copy 34:literal
   13:number <- copy 35:literal
   14:number <- copy 36:literal
-  15:point-number <- copy 12:point-number
+  15:point-number <- copy 12:point-number/raw  # unsafe
 ]
 +mem: storing 36 in location 17
 
@@ -57,7 +60,7 @@ recipe main [
   4:number <- copy 34:literal  # second
   5:number <- copy 35:literal
   6:number <- copy 36:literal
-  7:boolean <- equal 1:point-number, 4:point-number
+  7:boolean <- equal 1:point-number/raw, 4:point-number/raw  # unsafe
 ]
 +mem: storing 1 in location 7
 
@@ -69,7 +72,7 @@ recipe main [
   4:number <- copy 34:literal  # second
   5:number <- copy 35:literal
   6:number <- copy 37:literal  # different
-  7:boolean <- equal 1:point-number, 4:point-number
+  7:boolean <- equal 1:point-number/raw, 4:point-number/raw  # unsafe
 ]
 +mem: storing 0 in location 7
 
@@ -91,7 +94,7 @@ if (t.kind == container) {
 recipe main [
   12:number <- copy 34:literal
   13:number <- copy 35:literal
-  15:number <- get 12:point, 1:offset
+  15:number <- get 12:point/raw, 1:offset  # unsafe
 ]
 +mem: storing 35 in location 15
 
@@ -129,7 +132,7 @@ recipe main [
   12:number <- copy 34:literal
   13:number <- copy 35:literal
   14:number <- copy 36:literal
-  15:number <- get 12:point-number, 1:offset
+  15:number <- get 12:point-number/raw, 1:offset  # unsafe
 ]
 +mem: storing 36 in location 15
 
@@ -139,7 +142,7 @@ recipe main [
 recipe main [
   12:number <- copy 34:literal
   13:number <- copy 35:literal
-  15:address:number <- get-address 12:point, 1:offset
+  15:address:number <- get-address 12:point/raw, 1:offset  # unsafe
 ]
 +mem: storing 13 in location 15
 
diff --git a/032array.cc b/032array.cc
index 0d8efc5c..de9a05f1 100644
--- a/032array.cc
+++ b/032array.cc
@@ -5,6 +5,9 @@
 //: elements of a fixed size, so you can't create containers containing arrays.
 //: Create containers containing addresses to arrays instead.
 
+//: Tests in this layer often explicitly setup memory before reading it as an
+//: array. Don't do this in general. I'm tagging exceptions with /raw to
+//: avoid warnings.
 :(scenario copy_array)
 # Arrays can be copied around with a single instruction just like numbers,
 # no matter how large they are.
@@ -13,7 +16,7 @@ recipe main [
   2:number <- copy 14:literal
   3:number <- copy 15:literal
   4:number <- copy 16:literal
-  5:array:number <- copy 1:array:number
+  5:array:number <- copy 1:array:number/raw  # unsafe
 ]
 +mem: storing 3 in location 5
 +mem: storing 14 in location 6
@@ -52,7 +55,7 @@ recipe main [
   2:number <- copy 14:literal
   3:number <- copy 15:literal
   4:number <- copy 16:literal
-  5:number <- index 1:array:number, 0:literal
+  5:number <- index 1:array:number/raw, 0:literal  # unsafe
 ]
 +mem: storing 14 in location 5
 
@@ -63,7 +66,7 @@ recipe main [
   3:number <- copy 15:literal
   4:number <- copy 16:literal
   5:number <- copy 0:literal
-  6:number <- index 1:array:number, 5:number
+  6:number <- index 1:array:number/raw, 5:number  # unsafe
 ]
 +mem: storing 14 in location 6
 
@@ -105,7 +108,7 @@ recipe main [
   2:number <- copy 14:literal
   3:number <- copy 15:literal
   4:number <- copy 16:literal
-  5:number <- index-address 1:array:number, 0:literal
+  5:number <- index-address 1:array:number/raw, 0:literal  # unsafe
 ]
 +mem: storing 2 in location 5
 
@@ -148,7 +151,7 @@ recipe main [
   2:number <- copy 14:literal
   3:number <- copy 15:literal
   4:number <- copy 16:literal
-  5:number <- length 1:array:number
+  5:number <- length 1:array:number/raw  # unsafe
 ]
 +mem: storing 3 in location 5
 
diff --git a/034exclusive_container.cc b/034exclusive_container.cc
index 6d8e3932..8247cb42 100644
--- a/034exclusive_container.cc
+++ b/034exclusive_container.cc
@@ -25,13 +25,16 @@ Type[tmp].element_names.push_back("i");
 Type[tmp].element_names.push_back("p");
 }
 
+//: Tests in this layer often explicitly setup memory before reading it as an
+//: array. Don't do this in general. I'm tagging exceptions with /raw to
+//: avoid warnings.
 :(scenario copy_exclusive_container)
 # Copying exclusive containers copies all their contents and an extra location for the tag.
 recipe main [
   1:number <- copy 1:literal  # 'point' variant
   2:number <- copy 34:literal
   3:number <- copy 35:literal
-  4:number-or-point <- copy 1:number-or-point
+  4:number-or-point <- copy 1:number-or-point/raw  # unsafe
 ]
 +mem: storing 1 in location 4
 +mem: storing 34 in location 5
@@ -69,7 +72,7 @@ recipe main [
   12:number <- copy 1:literal
   13:number <- copy 35:literal
   14:number <- copy 36:literal
-  20:address:point <- maybe-convert 12:number-or-point, 1:variant
+  20:address:point <- maybe-convert 12:number-or-point/raw, 1:variant  # unsafe
 ]
 +mem: storing 13 in location 20
 
@@ -78,7 +81,7 @@ recipe main [
   12:number <- copy 1:literal
   13:number <- copy 35:literal
   14:number <- copy 36:literal
-  20:address:point <- maybe-convert 12:number-or-point, 0:variant
+  20:address:point <- maybe-convert 12:number-or-point/raw, 0:variant  # unsafe
 ]
 +mem: storing 0 in location 20
 
diff --git a/037call_reply.cc b/037call_reply.cc
index 4806c169..a6ec8c0c 100644
--- a/037call_reply.cc
+++ b/037call_reply.cc
@@ -51,7 +51,7 @@ recipe main [
 recipe f [
   12:number <- next-ingredient
   13:number <- copy 35:literal
-  reply 12:point
+  reply 12:point/raw  # unsafe
 ]
 +run: result 0 is [2, 35]
 +mem: storing 2 in location 3
diff --git a/041name.cc b/041name.cc
index 24ba4e00..eec6aa3e 100644
--- a/041name.cc
+++ b/041name.cc
@@ -31,6 +31,7 @@ void transform_names(const recipe_number r) {
   bool names_used = false;
   bool numeric_locations_used = false;
   map<string, long long int>& names = Name[r];
+  map<string, vector<type_number> > metadata;
   // store the indices 'used' so far in the map
   long long int& curr_idx = names[""];
   ++curr_idx;  // avoid using index 0, benign skip in some other cases
@@ -39,6 +40,7 @@ void transform_names(const recipe_number r) {
     // Per-recipe Transforms
     // map names to addresses
     for (long long int in = 0; in < SIZE(inst.ingredients); ++in) {
+      check_metadata(metadata, inst.ingredients.at(in), r);
       if (is_numeric_location(inst.ingredients.at(in))) numeric_locations_used = true;
       if (is_named_location(inst.ingredients.at(in))) names_used = true;
       if (disqualified(inst.ingredients.at(in))) continue;
@@ -48,6 +50,7 @@ void transform_names(const recipe_number r) {
       inst.ingredients.at(in).set_value(lookup_name(inst.ingredients.at(in), r));
     }
     for (long long int out = 0; out < SIZE(inst.products); ++out) {
+      check_metadata(metadata, inst.products.at(out), r);
       if (is_numeric_location(inst.products.at(out))) numeric_locations_used = true;
       if (is_named_location(inst.products.at(out))) names_used = true;
       if (disqualified(inst.products.at(out))) continue;
@@ -63,6 +66,15 @@ void transform_names(const recipe_number r) {
     raise << "mixing variable names and numeric addresses in " << Recipe[r].name << '\n';
 }
 
+void check_metadata(map<string, vector<type_number> >& metadata, const reagent& x, const recipe_number r) {
+  if (isa_literal(x)) return;
+  if (is_raw(x)) return;
+  if (metadata.find(x.name) == metadata.end())
+    metadata[x.name] = x.types;
+  if (metadata[x.name] != x.types)
+    raise << x.name << " used with multiple types in " << Recipe[r].name << '\n';
+}
+
 bool disqualified(/*mutable*/ reagent& x) {
   if (x.types.empty())
     raise << "missing type in " << x.to_string() << '\n';
@@ -180,6 +192,14 @@ recipe main [
 ]
 -warn: mixing variable names and numeric addresses in main
 
+:(scenario convert_names_warns_on_reusing_name_with_different_type)
+% Hide_warnings = true;
+recipe main [
+  x:number <- copy 1:literal
+  x:boolean <- copy 1:literal
+]
++warn: x used with multiple types in main
+
 //:: Support element names for containers in 'get' and 'get-address'.
 
 //: update our running example container for the next test
@@ -228,7 +248,7 @@ recipe main [
   12:number <- copy 1:literal
   13:number <- copy 35:literal
   14:number <- copy 36:literal
-  20:address:point <- maybe-convert 12:number-or-point, p:variant
+  20:address:point <- maybe-convert 12:number-or-point/raw, p:variant  # unsafe
 ]
 +name: variant p of type number-or-point has tag 1
 +mem: storing 13 in location 20