* don't transform div-by-power-of-2 into a shift when overflow checking is

enabled (mantis #23849)

git-svn-id: trunk@26089 -
This commit is contained in:
Jonas Maebe 2013-11-14 15:47:49 +00:00
parent f02dd9fde9
commit b6d279d4aa
3 changed files with 32 additions and 7 deletions

1
.gitattributes vendored
View File

@ -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

View File

@ -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
tests/webtbs/tw23849.pp Normal file
View File

@ -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.