* fixed missing masking of values after shifting them during inline

evaluation
   o also only mask values when performing a constant evaluation of
     "0 shl/shr x" during inline evaluation (just like when evaluating other
     shl/shr operations)

git-svn-id: trunk@43497 -
This commit is contained in:
Jonas Maebe 2019-11-16 14:27:47 +00:00
parent 851accbb4b
commit 4fd670c6ec
3 changed files with 47 additions and 28 deletions

1
.gitattributes vendored
View File

@ -14717,6 +14717,7 @@ tests/test/tinline9.pp svneol=native#text/plain
tests/test/tinlrange1.pp svneol=native#text/plain
tests/test/tinlrange2.pp svneol=native#text/plain
tests/test/tinlrange3.pp svneol=native#text/plain
tests/test/tinlrange4.pp svneol=native#text/plain
tests/test/tint2str1.pp svneol=native#text/plain
tests/test/tint2str2.pp svneol=native#text/plain
tests/test/tint641.pp svneol=native#text/plain

View File

@ -709,32 +709,32 @@ implementation
rvalue:=tordconstnode(right).value;
if is_constintnode(left) then
begin
lvalue:=tordconstnode(left).value;
case nodetype of
shrn:
lvalue:=tordconstnode(left).value shr rvalue;
shln:
lvalue:=tordconstnode(left).value shl rvalue;
else
internalerror(2019050517);
end;
if forinline then
begin
{ shl/shr are unsigned operations, so cut off upper bits }
case resultdef.size of
1:
lvalue:=tordconstnode(left).value and byte($ff);
lvalue:=lvalue and byte($ff);
2:
lvalue:=tordconstnode(left).value and word($ffff);
lvalue:=lvalue and word($ffff);
4:
lvalue:=tordconstnode(left).value and dword($ffffffff);
lvalue:=lvalue and dword($ffffffff);
8:
lvalue:=tordconstnode(left).value and qword($ffffffffffffffff);
lvalue:=lvalue and qword($ffffffffffffffff);
else
internalerror(2013122301);
end;
end
else
lvalue:=tordconstnode(left).value;
case nodetype of
shrn:
result:=create_simplified_ord_const(lvalue shr rvalue,resultdef,forinline,false);
shln:
result:=create_simplified_ord_const(lvalue shl rvalue,resultdef,forinline,false);
else
internalerror(2019050517);
end;
end;
result:=create_simplified_ord_const(lvalue,resultdef,forinline,false);
end
else if rvalue=0 then
begin
@ -745,19 +745,22 @@ implementation
else if is_constintnode(left) then
begin
lvalue:=tordconstnode(left).value;
{ shl/shr are unsigned operations, so cut off upper bits }
case resultdef.size of
1:
lvalue:=tordconstnode(left).value and byte($ff);
2:
lvalue:=tordconstnode(left).value and word($ffff);
4:
lvalue:=tordconstnode(left).value and dword($ffffffff);
8:
lvalue:=tordconstnode(left).value and qword($ffffffffffffffff);
else
internalerror(2013122301);
end;
if forinline then
begin
{ shl/shr are unsigned operations, so cut off upper bits }
case resultdef.size of
1:
lvalue:=tordconstnode(left).value and byte($ff);
2:
lvalue:=tordconstnode(left).value and word($ffff);
4:
lvalue:=tordconstnode(left).value and dword($ffffffff);
8:
lvalue:=tordconstnode(left).value and qword($ffffffffffffffff);
else
internalerror(2013122301);
end;
end;
{ '0 shl x' and '0 shr x' are 0 }
if (lvalue=0) and
((cs_opt_level4 in current_settings.optimizerswitches) or

15
tests/test/tinlrange4.pp Normal file
View File

@ -0,0 +1,15 @@
{ %norun }
{ %opt=-Sew }
{$r+}
{$warnings on}
const
MH_MAGIC = $feedface;
var
c: cardinal;
begin
c:= NToBE(MH_MAGIC);
end.