Pārlūkot izejas kodu

* don't transform div-by-power-of-2 into a shift when overflow checking is
enabled (mantis #23849)

git-svn-id: trunk@26089 -

Jonas Maebe 11 gadi atpakaļ
vecāks
revīzija
b6d279d4aa
3 mainītis faili ar 32 papildinājumiem un 7 dzēšanām
  1. 1 0
      .gitattributes
  2. 8 7
      compiler/arm/narmmat.pas
  3. 23 0
      tests/webtbs/tw23849.pp

+ 1 - 0
.gitattributes

@@ -13590,6 +13590,7 @@ tests/webtbs/tw2377.pp svneol=native#text/plain
 tests/webtbs/tw2378.pp svneol=native#text/plain
 tests/webtbs/tw23819.pp svneol=native#text/plain
 tests/webtbs/tw2382.pp svneol=native#text/plain
+tests/webtbs/tw23849.pp svneol=native#text/plain
 tests/webtbs/tw2388.pp svneol=native#text/plain
 tests/webtbs/tw23912.pp svneol=native#text/plain
 tests/webtbs/tw23962.pp svneol=native#text/plain

+ 8 - 7
compiler/arm/narmmat.pas

@@ -71,13 +71,14 @@ implementation
       var
         power  : longint;
       begin
-        if (right.nodetype=ordconstn) and
-          (nodetype=divn) and
-          (ispowerof2(tordconstnode(right).value,power) or
-           (tordconstnode(right).value=1) or
-           (tordconstnode(right).value=int64(-1))
-          ) and
-          not(is_64bitint(resultdef)) then
+        if not(cs_check_overflow in current_settings.localswitches) and
+           (right.nodetype=ordconstn) and
+           (nodetype=divn) and
+           (ispowerof2(tordconstnode(right).value,power) or
+            (tordconstnode(right).value=1) or
+            (tordconstnode(right).value=int64(-1))
+           ) and
+           not(is_64bitint(resultdef)) then
           result:=nil
         else if ((GenerateThumbCode) and (CPUARM_HAS_THUMB_IDIV in cpu_capabilities[current_settings.cputype])) and
           (nodetype=divn) and

+ 23 - 0
tests/webtbs/tw23849.pp

@@ -0,0 +1,23 @@
+{$mode delphi}
+{$q+}
+
+function F(N: integer) : integer;
+var NN : integer;
+begin
+    NN := N;
+    if NN < 0 then NN := 0 - NN;
+    result := NN;
+end;
+
+procedure Crash; cdecl;
+var
+    N, M : integer;
+begin
+    N := -10;
+    M := F(N) div 4;
+end;
+
+begin
+  Crash;
+end.
+