Ver Fonte

Fixed bug that caused over-aggressive copy propagation

Taddeus Kroes há 12 anos atrás
pai
commit
7dae809b98

+ 5 - 4
phases/constprop.ml

@@ -19,16 +19,17 @@ open Types
 open Util
 
 let is_const = function
-  | Const _
-  | VarUse (_, None, _) -> true
-  | _ -> false
+  | Const _               -> true
+  | VarUse (dec, None, _) -> is_const_id (nameof dec)
+  | Var (name, _, _)      -> is_const_id name
+  | _                     -> false
 
 (* Play-it-safe side effect analysis: only return true for variables and
  * constants, since these are targeted in arithmetic simplification (in
  * particular targeting array indices that can be simplified after array
  * dimension reduction). *)
 let no_side_effect = function
-  | VarUse _ | Const _ | Var _ -> true
+  | Const _ | VarUse _ | Var _ -> true
   | _ -> false
 
 (* Redefine integer operators within this module since they are only used on

+ 14 - 0
test/basic/functional/forloop_advanced.cvc

@@ -0,0 +1,14 @@
+extern void printInt(int val);
+extern void printNewlines(int num);
+
+export int main() {
+    int x = 10;
+    int y = 100;
+    for(int i = 0, y, x) {
+        x = x + 1;
+        y = y + 5;
+        printInt(i);
+        printNewlines(1);
+    }
+    return 0;
+}

+ 10 - 0
test/basic/functional/forloop_advanced.out

@@ -0,0 +1,10 @@
+0
+10
+20
+30
+40
+50
+60
+70
+80
+90