From 857e432896f106ad8340e4f8f20a955cd2a10d33 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Mon, 10 Sep 2018 19:29:16 -0500 Subject: [PATCH] Disable a native-code optimization that was generating bad code for %. Specifically, it converted PLX followed by PHA to STA 1,S. This is invalid if the x value is actually used, which is a case that can come up in the code now generated for the % operator. It might be possible to re-enable this optimization with tighter checks about where it's applied, but I don't think it's terribly important. The below program demonstrates an example that was being miscompiled: #pragma optimize -1 #include int main(void) { int a = 100, b = 200, c = 3, d = 4; printf("%i\n", (a+b) % (c+d)); /* should be 6 */ } --- Native.pas | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Native.pas b/Native.pas index c9daba9..332175d 100644 --- a/Native.pas +++ b/Native.pas @@ -1666,7 +1666,8 @@ var Remove(ns); end; {if} - m_plx: + {disabled - can generate bad code if the x value is used} + {m_plx: if npeep[ns+1].opcode = m_pha then begin opcode := m_sta_s; mode := direct;