Browse Source

* load a dummy value on the fpu stack in the epilog of functions
which return a real but which never assigned anything to the function
result (since the caller will pop it off again) (x86-only, bug #4902)

git-svn-id: trunk@3016 -

Jonas Maebe 19 years ago
parent
commit
1e3137c315
3 changed files with 26 additions and 1 deletions
  1. 1 0
      .gitattributes
  2. 9 1
      compiler/ncgutil.pas
  3. 16 0
      tests/webtbs/tw4902.pp

+ 1 - 0
.gitattributes

@@ -6760,6 +6760,7 @@ tests/webtbs/tw4893a.pp svneol=native#text/plain
 tests/webtbs/tw4893b.pp svneol=native#text/plain
 tests/webtbs/tw4893c.pp svneol=native#text/plain
 tests/webtbs/tw4898.pp -text
+tests/webtbs/tw4902.pp -text
 tests/webtbs/tw4922.pp svneol=native#text/plain
 tests/webtbs/ub1873.pp svneol=native#text/plain
 tests/webtbs/ub1883.pp svneol=native#text/plain

+ 9 - 1
compiler/ncgutil.pas

@@ -1258,7 +1258,15 @@ implementation
               else
                 internalerror(200405025);
             end;
-         end;
+          end
+{$ifdef x86}
+         else
+          begin
+            { the caller will pop a value off the cpu stack }
+            if (funcretloc.loc = LOC_FPUREGISTER) then
+              list.concat(taicpu.op_none(A_FLDZ));
+          end;
+{$endif x86}
       end;
 
 

+ 16 - 0
tests/webtbs/tw4902.pp

@@ -0,0 +1,16 @@
+{ Source provided for Free Pascal Bug Report 4902 }
+{ Submitted by "Yu Hang" on  2006-03-14 }
+{ e-mail: [email protected] }
+function x:real;
+begin
+end;
+
+begin
+x;
+{anything here}
+ writeln(1);
+ writeln(2);
+ writeln(3);
+{crash here}
+writeln(1.0)
+end.