Browse Source

* fixed multiplication by 64-bit constants on x86_64, mantis #26230

git-svn-id: trunk@27822 -
nickysn 11 years ago
parent
commit
daf71e6d88
3 changed files with 24 additions and 1 deletions
  1. 1 0
      .gitattributes
  2. 1 1
      compiler/x86/cgx86.pas
  3. 22 0
      tests/webtbs/tw26230.pp

+ 1 - 0
.gitattributes

@@ -13931,6 +13931,7 @@ tests/webtbs/tw2602.pp svneol=native#text/plain
 tests/webtbs/tw2607.pp svneol=native#text/plain
 tests/webtbs/tw2607.pp svneol=native#text/plain
 tests/webtbs/tw26162.pp svneol=native#text/pascal
 tests/webtbs/tw26162.pp svneol=native#text/pascal
 tests/webtbs/tw2620.pp svneol=native#text/plain
 tests/webtbs/tw2620.pp svneol=native#text/plain
+tests/webtbs/tw26230.pp svneol=native#text/plain
 tests/webtbs/tw2626.pp svneol=native#text/plain
 tests/webtbs/tw2626.pp svneol=native#text/plain
 tests/webtbs/tw2627.pp svneol=native#text/plain
 tests/webtbs/tw2627.pp svneol=native#text/plain
 tests/webtbs/tw2631.pp svneol=native#text/plain
 tests/webtbs/tw2631.pp svneol=native#text/plain

+ 1 - 1
compiler/x86/cgx86.pas

@@ -1589,7 +1589,7 @@ unit cgx86;
             list.concat(taicpu.op_ref_reg(A_LEA,TCgSize2OpSize[size],href,dst));
             list.concat(taicpu.op_ref_reg(A_LEA,TCgSize2OpSize[size],href,dst));
           end
           end
         else if (op in [OP_MUL,OP_IMUL]) and (size in [OS_32,OS_S32,OS_64,OS_S64]) and
         else if (op in [OP_MUL,OP_IMUL]) and (size in [OS_32,OS_S32,OS_64,OS_S64]) and
-          (a>1) and not ispowerof2(int64(a),power) then
+          (a>1) and (a<=maxLongint) and not ispowerof2(int64(a),power) then
           begin
           begin
             { MUL with overflow checking should be handled specifically in the code generator }
             { MUL with overflow checking should be handled specifically in the code generator }
             if (op=OP_MUL) and (cs_check_overflow in current_settings.localswitches) then
             if (op=OP_MUL) and (cs_check_overflow in current_settings.localswitches) then

+ 22 - 0
tests/webtbs/tw26230.pp

@@ -0,0 +1,22 @@
+program tw26230;
+
+const
+    C1 = 86400000000; //MCS in a day
+
+var
+    AInput,
+        Product : Int64;
+
+begin
+    AInput := 1;
+    //asm int3 end; //debug trap; `disassemble`
+    Product := AInput * C1;
+    WriteLn(AInput, ' * ', C1, ' = ', Product);
+    if Product <> 86400000000 then
+    begin
+      Writeln('Error!');
+      Halt(1);
+    end
+    else
+      Writeln('Ok');
+end.