Browse Source

[analyzer] don't fuse unops too far

closes #7704
Simon Krajewski 6 years ago
parent
commit
e9680cd354
2 changed files with 27 additions and 1 deletions
  1. 2 1
      src/optimization/analyzerTexpr.ml
  2. 25 0
      tests/optimization/src/issues/Issue7704.hx

+ 2 - 1
src/optimization/analyzerTexpr.ml

@@ -989,7 +989,8 @@ module Fusion = struct
 				begin try
 					let e2,f = match e2.eexpr with
 						| TReturn (Some e2) -> e2,(fun e -> {e2 with eexpr = TReturn (Some e)})
-						| TBinop(OpAssign,e21,e22) -> e22,(fun e -> {e2 with eexpr = TBinop(OpAssign,e21,e)})
+						(* This is not sound if e21 contains the variable (issue #7704) *)
+						(* | TBinop(OpAssign,e21,e22) -> e22,(fun e -> {e2 with eexpr = TBinop(OpAssign,e21,e)}) *)
 						| TVar(v,Some e2) -> e2,(fun e -> {e2 with eexpr = TVar(v,Some e)})
 						| _ -> raise Exit
 					in

+ 25 - 0
tests/optimization/src/issues/Issue7704.hx

@@ -0,0 +1,25 @@
+package issues;
+
+class Issue7704 {
+	@:js('
+		var i = 0;
+		var a = [];
+		a[i] = i;
+		++i;
+		a[i] = i;
+		issues_Issue7704.use(a);
+	')
+	@:analyzer(no_optimize)
+	static function test() {
+		var i = 0;
+		var a = [];
+
+		a[i] = i;
+		i++;
+		a[i] = i;
+
+		use(a);
+	}
+
+	@:pure(false) static function use(a) { }
+}