http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56098
--- Comment #6 from werner at almesberger dot net 2013-01-25 22:46:17 UTC ---
Thanks for the analysis and the fixes ! I'll try them soonish.
Regarding work-arounds, the ones I mentioned for my original code snippet
(i.e., -O1 or -fno-strict-aliasing) aren't sufficient in the following more
general case:
volatile void *p;
#define P (*(volatile int *) (p+8))
void foo(int x)
{
P = 1;
if (x)
P = 2;
}
This is for gcc (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2 on x86-64. The offset (8)
may be architecture-specific. For values < 8, correct code is generated with
-O1 (but not -O2 or higher).
The good news is that -fno-tree-cselim does indeed avoid the bad read in all
cases I've tried, with any optimization level.