Fix crash or error in certain cases when using common subexpression elimination.

In certain rare cases, constant subexpression elimination could set the left subtree of a pc_bno operation in the intermediate code to nil. This could lead to null pointer dereferences, sometimes resulting in a crash or error during native code generation.

The below program sometimes demonstrates the problem (dependent on zero page contents):

#pragma optimize 16
struct F {int *p;};
void foo(struct F* f)
{
    struct {int c;} s = {0};
    ++f->p;
    s.c |= *--f->p;
}
This commit is contained in:
Stephen Heumann 2019-12-16 17:13:14 -06:00
parent 8b339a9ab7
commit a09581b84e
1 changed files with 5 additions and 0 deletions

View File

@ -2531,6 +2531,11 @@ var
end {if}
else
op2 := op3^.left;
if op2 = nil then begin
op2 := pointer(Calloc(sizeof(intermediate_code)));
op2^.opcode := pc_nop;
op2^.optype := cgWord;
end; {if}
op1^.left := op3; {place in the new location}
end; {Combine}