[Bug c/87237] New: __atomic_load on 8-byte-sized, 1-byte-aligned struct is not atomic
richard-gccbugzilla at metafoo dot co.uk
gcc-bugzilla@gcc.gnu.org
Wed Sep 5 19:37:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87237
Bug ID: 87237
Summary: __atomic_load on 8-byte-sized, 1-byte-aligned struct
is not atomic
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: richard-gccbugzilla at metafoo dot co.uk
Target Milestone: ---
It's my understanding that __atomic_load is supposed to work for an essentially
arbitrary TYPE, including the case where alignof(TYPE) < sizeof(TYPE). (From
the documentation, "The four non-arithmetic functions (load, store, exchange,
and compare_exchange) all have a generic version as well. This generic version
works on any data type.") However:
struct A { char c[4]; } *p, *q;
void f() { __atomic_load(p, q, 5); }
On x86_64, GCC emits f as a 'movl' from *p. That is not atomic if *p straddles
two cache lines.
libatomic's __atomic_load implementation gets this right, and falls back on a
mutex in the case where the source straddles two cache lines, but GCC doesn't
seem to realize it needs to call it.
More information about the Gcc-bugs
mailing list