From 6e5860cb8753189d62529ab327e07f6b83d0e629 Mon Sep 17 00:00:00 2001 From: florian Date: Sun, 12 Nov 2023 22:30:09 +0100 Subject: [PATCH] * check for *-1 multiplications after folding, resolves #40448 --- compiler/nadd.pas | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/compiler/nadd.pas b/compiler/nadd.pas index 581e76fe9f..5d52f12e6e 100644 --- a/compiler/nadd.pas +++ b/compiler/nadd.pas @@ -846,9 +846,6 @@ implementation } result := ctypeconvnode.create_internal(PruneKeepLeft(),resultdef) - else if (tordconstnode(right).value = -1) and (nodetype=muln) then - result := ctypeconvnode.create_internal(cunaryminusnode.create(PruneKeepLeft()),ld) - { try to fold op op / \ / \ @@ -888,6 +885,15 @@ implementation end; end end; + + if assigned(result) then + exit; + + { multiplication by -1? Convert it into an unary minus if the other conversions before failed, don't do + it before the folding above, see #40448 } + if (tordconstnode(right).value = -1) and (nodetype=muln) then + result := ctypeconvnode.create_internal(cunaryminusnode.create(PruneKeepLeft()),ld); + if assigned(result) then exit; end;