totalspectrum / spin2cpp

Tool to convert Parallax Propeller Spin code to PASM, C++ or C
Other
46 stars 17 forks source link

Moving structs computes address multiple times (including side-effects!) #429

Closed Wuerfel21 closed 8 months ago

Wuerfel21 commented 9 months ago
struct vec3 {
    int x,y,z;
};
struct vec3 somesuch[5];
int main() {
    int i = 0, j = 1;
    __builtin_printf("i = %d; j = %d\n",i,j);
    somesuch[j++] = somesuch[i++];
    __builtin_printf("i = %d; j = %d\n",i,j);
}

produces, against all nature:

i = 0; j = 1
i = 3; j = 4

(and terrible codegen, too)

totalspectrum commented 8 months ago

Thanks for the bug report. I had some trouble figuring out what the best way to fix this is, but I think I have it now.