Fix bug where ++/-- operations would use the wrong location for local variables that don't fit in the direct page.

The code would trash other data on the stack, which could corrupt other variables and in some cases lead to crashes.

The following program (derived from a csmith-generated test case) shows the problem:

#pragma optimize -1
int main(void) {
    char arr[256] = {0};
    char l_565[3][2] = {{3,4}, {5,6}, {7,8}};
    l_565[0][0]++;
    return l_565[0][0];
}
This commit is contained in:
Stephen Heumann 2018-03-27 23:01:39 -05:00
parent 7605b7bbf2
commit 37cf771eee

View File

@ -1893,13 +1893,13 @@ case op^.optype of
else begin
GenNative(m_ldx_imm, immediate, gLong.disp, nil, 0);
if (not skipLoad) and (opcode in [pc_ili,pc_ild]) then
GenNative(m_lda_dirX, direct, gLong.disp, nil, 0);
GenNative(m_lda_dirX, direct, 0, nil, 0);
if opcode in [pc_ili,pc_iil] then
GenNative(m_inc_dirX, direct, gLong.disp, nil, 0)
GenNative(m_inc_dirX, direct, 0, nil, 0)
else
GenNative(m_dec_dirX, direct, gLong.disp, nil, 0);
GenNative(m_dec_dirX, direct, 0, nil, 0);
if (not skipLoad) and (opcode in [pc_iil,pc_idl]) then
GenNative(m_lda_dirX, direct, gLong.disp, nil, 0);
GenNative(m_lda_dirX, direct, 0, nil, 0);
end; {else}
if short then
GenNative(m_rep, immediate, 32, nil, 0);