From 2413d4b43f4be180d68cfafae00e24c99263009b Mon Sep 17 00:00:00 2001 From: Jonas Maebe <jonas@freepascal.org> Date: Sat, 26 Apr 2008 21:22:08 +0000 Subject: [PATCH] * fixed constant evaluation check for negvalue+posvalue (mantis #11216) git-svn-id: trunk@10808 - --- .gitattributes | 1 + compiler/constexp.pas | 2 +- tests/webtbs/tw11216.pp | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/webtbs/tw11216.pp diff --git a/.gitattributes b/.gitattributes index ff939bdea3..7ab3a0be9a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -8144,6 +8144,7 @@ tests/webtbs/tw1111.pp svneol=native#text/plain tests/webtbs/tw11139.pp svneol=native#text/plain tests/webtbs/tw11169.pp svneol=native#text/plain tests/webtbs/tw1117.pp svneol=native#text/plain +tests/webtbs/tw11216.pp svneol=native#text/plain tests/webtbs/tw1122.pp svneol=native#text/plain tests/webtbs/tw1123.pp svneol=native#text/plain tests/webtbs/tw1124.pp svneol=native#text/plain diff --git a/compiler/constexp.pas b/compiler/constexp.pas index c3a5c33baf..3ecb2d7612 100644 --- a/compiler/constexp.pas +++ b/compiler/constexp.pas @@ -160,7 +160,7 @@ begin {Try if the result fits in an int64.} if (a.signed) and (a.svalue<0) then {$Q-} - sspace:=qword(high(int64))-qword(-a.svalue) + sspace:=qword(high(int64))+qword(-a.svalue) {$ifdef ena_q}{$Q+}{$endif} else if not a.signed and (a.uvalue>qword(high(int64))) then goto try_qword diff --git a/tests/webtbs/tw11216.pp b/tests/webtbs/tw11216.pp new file mode 100644 index 0000000000..1478b63e8f --- /dev/null +++ b/tests/webtbs/tw11216.pp @@ -0,0 +1,21 @@ +program TestRC; +{$R+} + +var Li, Lj : Int64; +const I = $7fffffffffffffff; + +begin + if (1-I)<>(-I+1) then + halt(1); + + writeln(1-I); + writeln(-I+1); + + Li := 1-I; + Lj := -I + 1; + if Li<>Lj then + halt(2); + + if (Li<>-9223372036854775806) then + halt(3); +end.