In current SDCC 3.6.9 #10093, the following code
struct
{
volatile int x;
} s;
void f(void)
{
s.x & 5;
while(s.x & 5);
}
Reads s.x only once. This is probably a bug in lospre, since the generated asm seems correct when using --nolospre.
Philipp
P.S.: This issues was first found and reported by Daniel Drotos on the sdcc-user mailing list. I just verified, tested, created a code sample to reproduce the issue and filed the bug report.
Diff:
confirmed on 3.7.0 and latest snapshot r10385, the following sample code also cause the problem:
Tried to modify SDCC source code, it seems that the patch in the attachment could fix the problem.
I'm looking into this, and hope to have a fix in the next few days. The patch would indeed fix the bug, but would also disable some valid optimizations, so I'll see if I can come up with a solution that allows for more optimizations on volatile variables.
Philipp
Fixed in [r10473].
Philipp