From a9f7f97a2fbe7f462403c3600a8f1762d5424480 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sat, 31 Mar 2018 20:10:50 -0500 Subject: [PATCH] Avoid errors from attempting common subexpression elimination on the left subexpression of the comma operator. This could happen because the left subexpression does not produce a result for use in the enclosing expression, and therefore is not of the form expected by the CSE code. The following program (derived from a csmith-generated test case) illustrates the problem: #pragma optimize 16 int main(void) { int i; i, (i, 1); } --- DAG.pas | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/DAG.pas b/DAG.pas index e378463..1325de9 100644 --- a/DAG.pas +++ b/DAG.pas @@ -2648,7 +2648,8 @@ var begin {Match} op2 := nil; {check for an exact match} skip := false; - if CodesMatch(op, tree, true) then begin + if not (op^.opcode in [pc_str,pc_sro]) and CodesMatch(op, tree, true) + then begin if op = tree then op2 := tree else begin @@ -2698,7 +2699,8 @@ var if op^.right <> nil then CheckTree(op^.right, bb); if op^.next = nil then {look for a match to the current code} - if not (op^.opcode in [pc_cup,pc_cui,pc_tl1,pc_bno]) then begin + if not (op^.opcode in [pc_cup,pc_cui,pc_tl1,pc_bno,pc_pop,pc_sto,pc_sbf]) + then begin op2 := nil; op3 := bb^.code; while (op2 = nil) and (op3 <> nil) do begin