Browse Source

* second mul might get called with a zero operand if the other has a side effect,
handle this correctly in ti386addnode.second_mul64bit, resolves #40182

florian 2 years ago
parent
commit
99b01f6634
2 changed files with 27 additions and 0 deletions
  1. 12 0
      compiler/i386/n386add.pas
  2. 15 0
      tests/webtbs/tw40182.pp

+ 12 - 0
compiler/i386/n386add.pas

@@ -573,6 +573,18 @@ interface
       { calculate 32-bit terms lo(right)*hi(left) and hi(left)*lo(right) }
       if (right.location.loc=LOC_CONSTANT) then
         begin
+          { if left has side effects, it could be that this code is called with right.location.value64=0,
+            see also #40182 }
+          if right.location.value64=0 then
+            begin
+              location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
+              location.register64.reglo := cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
+              emit_const_reg(A_MOV,S_L,0,location.register64.reglo);
+              location.register64.reghi := cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
+              emit_const_reg(A_MOV,S_L,0,location.register64.reghi);
+              exit;
+            end;
+
           { Omit zero terms, if any }
           hreg1:=NR_NO;
           hreg2:=NR_NO;

+ 15 - 0
tests/webtbs/tw40182.pp

@@ -0,0 +1,15 @@
+{ %opt=-CO }
+
+program test;
+function somenumber: int64;
+begin
+  exit(2);
+end;
+
+function foo: int64;
+begin
+  exit (0*somenumber); //Internal error 2014011604
+end;
+
+begin
+end.