From db98f7842d80c4241f273569d4a1c5c0b3de823c Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Mon, 26 Mar 2018 18:20:36 -0500 Subject: [PATCH] Fix mis-evaluation of certain equality comparisons with intermediate code optimization. This affected comparisons of the form "logical operation or comparison == constant other than 0 or 1". These should always evaluate to 0 (false), but could mis-evaluate to true due to the bad optimization. The following program gives an example showing the problem: #pragma optimize 1 int main(void) { int i = 0, j = 42; return (i || j) == 123; } --- DAG.pas | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DAG.pas b/DAG.pas index 36cefd7..c5e2121 100644 --- a/DAG.pas +++ b/DAG.pas @@ -1329,7 +1329,7 @@ case op^.opcode of {check for optimizations of this node} end; {case} end {if} else if op^.right^.optype in [cgByte, cgUByte, cgWord, cgUWord] then begin - if op^.right^.q <> 0 then + if op^.right^.q = 1 then if op^.left^.opcode in [pc_and,pc_ior,pc_neq,pc_equ,pc_geq,pc_leq,pc_les,pc_grt] then begin @@ -1338,7 +1338,7 @@ case op^.opcode of {check for optimizations of this node} end; {if} end {else if} else if op^.right^.optype in [cgLong, cgULong] then begin - if op^.right^.lval <> 0 then + if op^.right^.lval = 1 then if op^.left^.opcode in [pc_and,pc_ior,pc_neq,pc_equ,pc_geq,pc_leq,pc_les,pc_grt] then begin