Don't optimize out certain volatile stores.

This could occur due to the new native-code peephole optimizations for stz instructions, which can collapse consecutive identical ones down to one instruction. This is OK most of the time, but not when dealing with volatile variables, so disable it in that case.

The following test case shows the issue (look at the generated code):

#pragma optimize -1
volatile int a;
int main(void) {
        a = 0;
        a = 0;
}
This commit is contained in:
Stephen Heumann 2018-01-07 21:50:32 -06:00
parent 38345e4ca2
commit 44714767e5
1 changed files with 4 additions and 2 deletions

View File

@ -1744,12 +1744,14 @@ var
if npeep[ns].opcode = npeep[ns+1].opcode then
if npeep[ns].operand = npeep[ns+1].operand then
if npeep[ns].name = npeep[ns+1].name then
Remove(ns+1);
if not volatile then
Remove(ns+1);
m_stz_dir, m_stz_dirX:
if npeep[ns].opcode = npeep[ns+1].opcode then
if npeep[ns].operand = npeep[ns+1].operand then
Remove(ns+1);
if not volatile then
Remove(ns+1);
otherwise: ;