Browse Source

* AArch64: avoid false overflow error in case of -2^63+0

florian 1 year ago
parent
commit
1fccfd3ee1
2 changed files with 10 additions and 27 deletions
  1. 3 1
      compiler/aarch64/cgcpu.pas
  2. 7 26
      tests/tbs/tb0712.pp

+ 3 - 1
compiler/aarch64/cgcpu.pas

@@ -1436,7 +1436,9 @@ implementation
       begin
         { add/sub instructions have only positive immediate operands }
         if (op in [OP_ADD,OP_SUB]) and
-           (a<0) then
+           (a<0) and
+           { this might result in a false positive overflow in case of a+0 }
+           (a<>$8000000000000000) then
           begin
             if op=OP_ADD then
               op:=op_SUB

+ 7 - 26
tests/tbs/tb0712.pp

@@ -1,28 +1,9 @@
-var
-  yy,res : longint;
-begin
-  res:=0;
-  yy:=random(0)+1980;
-  If (yy<1980) or (yy>2099) then
-    res:=1;
-  if res<>0 then
-    halt(res);
-
-  yy:=random(0)+2099;
-  If (yy<1980) or (yy>2099) then
-    res:=2;
-  if res<>0 then
-    halt(res);
+{$mode objfpc}
 
-  yy:=random(0)+1980;
-  If (yy<=1979) or (yy>2099) then
-    res:=3;
-  if res<>0 then
-    halt(res);
+{$Q+}
+uses
+  Sysutils;
 
-  yy:=random(0)+2099;
-  If (yy<1979) or (yy>=2100) then
-    res:=4;
-  if res<>0 then
-    halt(res);
-end.
+begin
+  writeln(Int64.MinValue+Int64(Random(0)));
+end.