Quellcode durchsuchen

* handle exit(<expr>) correctly in the dfa, resolves #11848

git-svn-id: trunk@11547 -
florian vor 17 Jahren
Ursprung
Commit
8cc0a04db5
4 geänderte Dateien mit 65 neuen und 3 gelöschten Zeilen
  1. 2 0
      .gitattributes
  2. 20 3
      compiler/optdfa.pas
  3. 20 0
      tests/webtbf/tw11848a.pp
  4. 23 0
      tests/webtbs/tw11848.pp

+ 2 - 0
.gitattributes

@@ -8096,6 +8096,7 @@ tests/webtbf/tw11295b.pp svneol=native#text/plain
 tests/webtbf/tw1157a.pp svneol=native#text/plain
 tests/webtbf/tw11619b.pp svneol=native#text/plain
 tests/webtbf/tw11632.pp svneol=native#text/plain
+tests/webtbf/tw11848a.pp svneol=native#text/plain
 tests/webtbf/tw1238.pp svneol=native#text/plain
 tests/webtbf/tw1251a.pp svneol=native#text/plain
 tests/webtbf/tw1270.pp svneol=native#text/plain
@@ -8531,6 +8532,7 @@ tests/webtbs/tw1157.pp svneol=native#text/plain
 tests/webtbs/tw1157b.pp svneol=native#text/plain
 tests/webtbs/tw11619.pp svneol=native#text/plain
 tests/webtbs/tw1181.pp svneol=native#text/plain
+tests/webtbs/tw11848.pp svneol=native#text/plain
 tests/webtbs/tw1203.pp svneol=native#text/plain
 tests/webtbs/tw1204.pp svneol=native#text/plain
 tests/webtbs/tw1207.pp svneol=native#text/plain

+ 20 - 3
compiler/optdfa.pas

@@ -403,9 +403,26 @@ unit optdfa;
                 if not(is_void(current_procinfo.procdef.returndef)) and
                   not(current_procinfo.procdef.proctypeoption=potype_constructor) then
                   begin
-                    { get info from faked resultnode }
-                    node.optinfo^.use:=resultnode.optinfo^.use;
-                    node.optinfo^.life:=node.optinfo^.use;
+                    if not(assigned(node.optinfo^.def)) and
+                       not(assigned(node.optinfo^.use)) then
+                      begin
+                        if assigned(texitnode(node).left) then
+                          begin
+                            node.optinfo^.def:=resultnode.optinfo^.def;
+
+                            dfainfo.use:[email protected]^.use;
+                            dfainfo.def:[email protected]^.def;
+                            dfainfo.map:=map;
+                            foreachnodestatic(pm_postprocess,texitnode(node).left,@AddDefUse,@dfainfo);
+                            calclife(node);
+                          end
+                        else
+                          begin
+                            { get info from faked resultnode }
+                            node.optinfo^.use:=resultnode.optinfo^.use;
+                            node.optinfo^.life:=node.optinfo^.use;
+                          end;
+                      end;
                   end;
               end;
 

+ 20 - 0
tests/webtbf/tw11848a.pp

@@ -0,0 +1,20 @@
+{ %OPT=-Sew -Oodfa }
+{ %FAIL }
+{$mode objfpc}{$H+}
+
+uses
+  Classes, SysUtils;
+
+function Test(a: integer): integer;
+var
+  i : integer;
+begin
+  if a>0 then
+    i:=1
+  else
+    exit(i);
+end;
+
+begin
+end.
+

+ 23 - 0
tests/webtbs/tw11848.pp

@@ -0,0 +1,23 @@
+{ %OPT=-Sew -Oodfa }
+{ %NORUN }
+{$mode objfpc}{$H+}
+
+uses
+  Classes, SysUtils;
+
+function Test(a: integer): integer;
+var
+  HashItem: Pointer;
+begin
+  HashItem:=nil;
+  while HashItem<>nil do begin
+    if (HashItem<>nil) then
+      exit(-1);
+    HashItem:=HashItem;
+  end;
+  Result:=0;
+end;
+
+begin
+end.
+