[cfe-dev] curious "apparent" gcc bug that clang seems to get right

reed kotler rkotler at mips.com
Wed Dec 4 20:51:23 PST 2013


I'm not sure myself enough of how, if at all, volatile is inherited into 
a class from it's members.
But the following code, boiled down from some complicated android code 
is essentially.

This same problem happens for gcc x86 and mips.

Anyone care to weigh in on a proper reading of the C or C++ standard for 
this?

Clang does what not have this problem.

/* mips-linux-gnu-gcc -S a.c -O3 */
/* gcc -S a.c -O3 */

union {
         volatile int y;
} i, j;

void works_as_expected(void) {
         do {
                 /* reads j, writes i */
                 i.y = j.y;
         } while (1);
}

void is_this_correct(void) {
         do {
                 /* mips: writes j, doesn't reread i */
                 /* x86: rereads j, doesn't write i */
                 i = j;
         } while(1);
}






More information about the cfe-dev mailing list