On Wed, Oct 23, 2013 at 9:11 AM, Bernd Edlinger <bernd.edlin...@hotmail.de> wrote: > Hi Richard/Joseph, > > I noticed, this test case crashes on arm-eabi already witout the patch. > > extern void abort (void); > > #define test_type unsigned short > #define MAGIC (unsigned short)0x102u > > typedef struct s{ > unsigned char Prefix[1]; > test_type Type; > }__attribute((__packed__,__aligned__(4))) ss; > > volatile ss v; > ss g; > > void __attribute__((noinline)) > foo (test_type u) > { > v.Type = u; > } > > test_type __attribute__((noinline)) > bar (void) > { > return v.Type; > } > > > However when compiled with -fno-strict-volatile-bitfields it does not crash, > but AFAIK the generated code for foo() violates the C++ memory model: > > foo: > @ Function supports interworking. > @ args = 0, pretend = 0, frame = 0 > @ frame_needed = 0, uses_anonymous_args = 0 > @ link register save eliminated. > ldr r2, .L2 > ldr r3, [r2] > bic r3, r3, #16711680 > bic r3, r3, #65280 > orr r3, r3, r0, asl #8 > str r3, [r2] > bx lr > > > On Intel the generated code uses unaligned access, but is OK for the memory > model: > > foo: > .LFB0: > .cfi_startproc > movw %di, v+1(%rip) > ret > > > Am I right, or is the code OK for the Memory model?
The C++ memory model says that you may not introduce a data-race and thus you have to access Type without touching Prefix. Richard. > Regards > Bernd.