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 <stdio.h>
int main(void) {
        int a = 100, b = 200, c = 3, d = 4;
        printf("%i\n", (a+b) % (c+d)); /* should be 6 */
}
This commit is contained in:
Stephen Heumann 2018-09-10 19:29:16 -05:00
parent a359543769
commit 857e432896
1 changed files with 2 additions and 1 deletions

View File

@ -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;