From 80b96c1147382c1b7f29ad7eda1889f793b34c88 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Fri, 14 Sep 2018 19:16:50 -0500 Subject: [PATCH] Ensure % with negative operands is not mis-optimized in intermediate code. This will not be triggered in most cases, but might be if one of the operand expressions was itself subject to optimization. --- DAG.pas | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DAG.pas b/DAG.pas index 1325de9..901b49b 100644 --- a/DAG.pas +++ b/DAG.pas @@ -1625,7 +1625,7 @@ case op^.opcode of {check for optimizations of this node} pc_mdl: begin {pc_mdl} if op^.right^.opcode = pc_ldc then if op^.left^.opcode = pc_ldc then - if op^.right^.lval <> 0 then begin + if (op^.left^.lval >= 0) and (op^.right^.lval > 0) then begin op^.left^.lval := op^.left^.lval mod op^.right^.lval; opv := op^.left; end; {if} @@ -1634,7 +1634,7 @@ case op^.opcode of {check for optimizations of this node} pc_mod: begin {pc_mod} if op^.right^.opcode = pc_ldc then if op^.left^.opcode = pc_ldc then - if op^.right^.q <> 0 then begin + if (op^.left^.q >= 0) and (op^.right^.q > 0) then begin op^.left^.q := op^.left^.q mod op^.right^.q; opv := op^.left; end; {if}