Fix bug causing incorrect code generation in programs that use the 'volatile' keyword.

This bug could both cause accesses to volatile variables to be omitted, and also cause other expressions to be erroneously optimized out in certain circumstances.

As an example, both the access of x and the call to bar() would be erroneously removed in the following program:

#pragma optimize 1
volatile int x;
int bar(void);
void foo(void)
{
    if(x) ;
    if(bar()) ;
}

Note that this patch disables even more optimizations than previously if the 'volatile' keyword is used anywhere in a translation unit. This is necessary for correctness given the current design of ORCA/C, but it means that care should be taken to avoid unnecessary use of 'volatile'.
This commit is contained in:
Stephen Heumann 2017-07-11 21:15:57 -05:00
parent fb612e14d1
commit 1502e48188
1 changed files with 8 additions and 2 deletions

10
DAG.pas
View File

@ -479,13 +479,19 @@ var
result: boolean; {temp result}
begin {SideEffects}
if (op = nil) or volatile then
SideEffects := false
if op = nil then begin
if volatile then
SideEffects := true
else
SideEffects := false
end {if}
else if op^.opcode in
[pc_mov,pc_cbf,pc_cop,pc_cpi,pc_cpo,pc_gil,pc_gli,pc_gdl,
pc_gld,pc_iil,pc_ili,pc_idl,pc_ild,pc_lil,pc_lli,pc_ldl,
pc_lld,pc_sbf,pc_sro,pc_sto,pc_str,pc_cui,pc_cup,pc_tl1] then
SideEffects := true
else if op^.opcode = pc_ldc then
SideEffects := false
else
SideEffects := SideEffects(op^.left) or SideEffects(op^.right);
end; {SideEffects}