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);
}
This commit is contained in:
Stephen Heumann 2018-03-26 19:57:18 -05:00
parent 7f94876fa8
commit f2d15b8fc7
1 changed files with 4 additions and 1 deletions

View File

@ -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;