[Bug ipa/80728] IPA-reference suppresses compiler memory barrier
pinskia at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Mar 27 04:24:06 GMT 2024
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80728
--- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I am not 100% sure we should not transform this code. The way signals are
defined that only volatile/atomic variables can be done via signals.
This works:
```
static _Atomic int i;
static _Atomic int b;
void sighandler(void)
{
__atomic_store_n (&b, 1, __ATOMIC_RELAXED);
__atomic_store_n (&i, 1, __ATOMIC_RELAXED);
}
__attribute__((noinline))
static int x(void)
{
asm volatile("":::"memory");
return __atomic_load_n(&b, __ATOMIC_RELAXED);
}
int f(void)
{
__atomic_store_n (&b, 0, __ATOMIC_RELAXED);
return x() ? __atomic_load_n(&i, __ATOMIC_RELAXED) : 0;
}
```
So does marking b/i as volatile.
Marking the variable i with the attribute used also works. as that says the
variable is used outside of what the compiler knows and in this case x only has
an inline-asm which clobbers memory.
More information about the Gcc-bugs
mailing list