A hypothetical example? Yes, compilers are allowed to turn
x = 0;
into
x = 1;
x = 0;
Now, a realistic example… that will be harder. One could imagine a compiler moving an assignment out of a conditional if it knows that it will be overwritten later anyway:
if foo {
x = 0;
} else {
x = 1;
bar();
}
could be turned into
x = 1;
if foo {
x = 0;
} else {
bar();
}
Still seems somewhat dump, but compilers do move assignments out of conditionals (and that is the reason for some of the quirks in relaxed accesses).
I will ask some people if they can come up with more realistic examples.