From f2d15b8fc757e55b40cbd5a5ff7dbbfa878e2bf1 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Mon, 26 Mar 2018 19:57:18 -0500 Subject: [PATCH] Fix optimizer bug where casts with unused results could sometimes cause stack corruption. This problem could lead to crashes in code like the following (derived from a csmith-generated test case): #pragma optimize 1 static int main(void) { long i = 2; (long)(i > 1); } --- DAG.pas | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/DAG.pas b/DAG.pas index 39a6984..daced54 100644 --- a/DAG.pas +++ b/DAG.pas @@ -1840,8 +1840,11 @@ case op^.opcode of {check for optimizations of this node} end; {case pc_not} pc_pop: begin {pc_pop} - if op^.left^.opcode = pc_cnv then + if op^.left^.opcode = pc_cnv then begin + fromtype.i := (op^.left^.q & $00F0) >> 4; + op^.optype := fromtype.optype; op^.left := op^.left^.left; + end; {if} opcode := op^.left^.opcode; if opcode = pc_cop then begin op^.left^.opcode := pc_str;