This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/71660] [5/6/7/8 regression] alignment of std::atomic<8 byte primitive type> (long long, double) is wrong on x86


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71660

--- Comment #14 from Thiago Macieira <thiago at kde dot org> ---
(In reply to Peter Cordes from comment #13)
> If you want a struct with non-atomic members to match the layout of a struct
> with atomic members, do something like
> 
> struct foo {
>     char c;
>     alignas(atomic<long long>) long long t;
> };
> 
[cut]
> IDK what Qt's assert is guarding against.  If you're specifically worried
> about atomicity, checking that alignof(InStruct) == sizeof(long long) makes
> more sense, because that's required on almost any architecture as a
> guaranteed way to avoid cache-line splits.  (C/C++ don't have a simple way
> to express "unaligned is fine except at cache line boundaries" like you get
> on Intel specifically (not AMD)).

It was trying to guard against exactly what you said above: that the alignment
of a QAtomicInteger<T> was exactly the same as the alignment of a plain T
inside a struct, so one could replace a previous plain member with an atomic
and keep binary compatibility. 

But it's clear now that atomic types may need extra alignment than the plain
types. In hindsight, the check is unnecessary and should be removed; people
should not expect to replace T with std::atomic<T> or QAtomicInteger<T> and
keep ABI.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]