From 59c77a48b5d4533ab71b5baddfa203186f39b0c2 Mon Sep 17 00:00:00 2001 From: florian Date: Tue, 5 Mar 2024 22:10:56 +0100 Subject: [PATCH] * transform -x-1 into not(x), resolves #40313 --- compiler/nadd.pas | 7 +++++++ tests/tbs/tb0711.pp | 9 +++++++++ 2 files changed, 16 insertions(+) create mode 100644 tests/tbs/tb0711.pp diff --git a/compiler/nadd.pas b/compiler/nadd.pas index 354868501c..1034c58083 100644 --- a/compiler/nadd.pas +++ b/compiler/nadd.pas @@ -932,6 +932,13 @@ implementation left:=nil; tmoddivnode(right).right:=nil; exit; + end + + { transform -x-1 into not(x) } + else if is_signed(ld) and is_constintnode(right) and (tordconstnode(right).value=1) and (left.nodetype=unaryminusn) then + begin + result:=cnotnode.create(tunaryminusnode(left).left.getcopy); + exit; end; end; diff --git a/tests/tbs/tb0711.pp b/tests/tbs/tb0711.pp new file mode 100644 index 0000000000..f9d8173bfa --- /dev/null +++ b/tests/tbs/tb0711.pp @@ -0,0 +1,9 @@ +var + l : longint; + +begin + l:=1234; + + if -l-1<>-1235 then + halt(1); +end. \ No newline at end of file