Fix issue where certain address computations could be improperly restricted to a 32K or 64K range (even when using the large memory model).

This could occur with computations where multiple variables were added to a pointer.

The following program is an example that was miscompiled:

#pragma optimize 1
#pragma memorymodel 1

char c[80000];

int main(void) {
    unsigned i = 30000, j = 40000;
    c[70000] = 3;
    return *(c+i+j); /* should return 3 */
}
This commit is contained in:
Stephen Heumann 2017-11-11 23:18:16 -06:00
parent 103af4c4a4
commit df42ce257f

15
DAG.pas
View File

@ -1522,11 +1522,16 @@ case op^.opcode of {check for optimizations of this node}
end; {if}
end {else if}
else if op^.left^.opcode = pc_ixa then begin
op2 := op^.left;
op^.left := op^.left^.left;
op2^.left := op^.right;
op2^.opcode := pc_adi;
op^.right := op2;
if smallMemoryModel then
if op^.left^.left^.opcode in [pc_lao,pc_lda] then
if op^.left^.left^.q = 0 then begin
op2 := op^.left;
op^.left := op^.left^.left;
op2^.left := op^.right;
op2^.opcode := pc_adi;
op^.right := op2;
op^.optype := cgUWord;
end; {if}
end; {else if}
end; {case pc_ixa}