From 44714767e521ae41d309df28e113c6d1f6daa0d0 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 7 Jan 2018 21:50:32 -0600 Subject: [PATCH] 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; } --- Native.pas | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Native.pas b/Native.pas index 5534f5f..717e5cf 100644 --- a/Native.pas +++ b/Native.pas @@ -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: ;