Simplify constexp.pas.
I tried to fix #40777 the obvious way of modifying operator shl(a, b: Tconstexprint): Tconstexprint
, and it indeed worked.
I also attempted to simplify some more of constexp.pas
(−25% LoC!), using this idea in particular. But while checking against existing implementations I found two more examples of wrong trunk behavior, C2
and C3
below, where C3
is NOT fixed by this MR:
const
C1 = 1 shl 63; // Trunk: silent −9223372036854775808. MR: correct 9223372036854775808.
C2 = High(uint64) - 2 - High(uint64); // Trunk: “Overflow in arithmetic operation”, MR: correct −2.
// C3 = High(int64) + 1 + -1; // “Overflow in arithmetic operation”, not fixed by the MR.
begin
{$if C1 < 0} {$error 1 shl 63 < 0} {$endif}
{$if C2 + 2 <> 0} {$error High(uint64) - 2 - High(uint64) <> -2} {$endif}
end.
C3
looks as if the compiler converts −1 to a qword
during the typecheck (did it have to do that???????), and then the addition of two qwords fails. It hasn’t gotten any worse, anyway.
Update: literal $8000000000000000
is also considered negative, so I added an explicit conversion to tconstprop1.pp for now
Edited by Rika