Browse Source

* calculate life info for if nodes correctly if the then branch is empty, resolves #39992

florian 2 years ago
parent
commit
3b43bd027c
2 changed files with 22 additions and 1 deletions
  1. 3 1
      compiler/optdfa.pas
  2. 19 0
      tests/webtbs/tw39992.pp

+ 3 - 1
compiler/optdfa.pas

@@ -449,7 +449,9 @@ unit optdfa;
 
                 { get life info from then branch }
                 if assigned(tifnode(node).right) then
-                  DFASetIncludeSet(l,tifnode(node).right.optinfo^.life);
+                  DFASetIncludeSet(l,tifnode(node).right.optinfo^.life)
+                else if assigned(node.successor) then
+                  DFASetIncludeSet(l,node.successor.optinfo^.life);
 
                 { get life info from else branch }
                 if assigned(tifnode(node).t1) then

+ 19 - 0
tests/webtbs/tw39992.pp

@@ -0,0 +1,19 @@
+{ %OPT=-O3 -Oodeadstore }
+
+{$mode objfpc}
+function ChooseMinus10: SizeInt;
+var
+	chosen: SizeInt;
+begin
+	chosen := -10;
+	repeat
+		if random(1) = 0 then else break;
+		exit(chosen);
+	until false;
+	result := -20;
+end;
+
+begin
+  if ChooseMinus10<>-10 then
+    halt(1);
+end.