[PATCH] D23719: [libc++] Use C11 for atomics check

Ben Craig via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 19 11:55:23 PDT 2016


bcraig added a comment.

In https://reviews.llvm.org/D23719#520969, @rsmith wrote:

> In https://reviews.llvm.org/D23719#520954, @bcraig wrote:
>
> > In https://reviews.llvm.org/D23719#520952, @rsmith wrote:
> >
> > > Are we really guaranteed that the C and C++ compiler behave the same way here? I don't see why that would necessarily be the case.
> >
> >
> > For libc++, std::atomic is implemented in terms of _Atomic.  So as long as the C++ compiler doesn't butcher _Atomic, it seems that the behavior would be the same.
>
>
> I don't see any good reason to assume that's the case. GCC, for instance, does not define _Atomic *at all* in C++ mode; the implementation used by libc++ in that case is completely different. Also, as far as I know, libc++ did not previously require the host to have a C11 compiler. And there's no reason to assume that the C compiler picked up by cmake is in any way related to the C++ compiler.
>
> Bottom line: if you want to know how the C++ compiler behaves, you need to test the C++ compiler not the C compiler.


I managed to completely miss "#define _Atomic(x) __gcc_atomic::__gcc_atomic_t<x>" in the atomic header.

On a different note, the general class of checks that LLVM and LIBCXX have in place to detect atomics generally don't work for cross-compilation.  The  set(CMAKE_REQUIRED_FLAGS ...) calls overwrite important settings.  I end up setting HAVE_CXX_ATOMICS_WITHOUT_LIB=ON, HAVE_CXX_ATOMICS64_WITHOUT_LIB=ON, and LIBCXX_HAVE_CXX_ATOMICS_WITHOUT_LIB=ON explicitly, because the automatic check just doesn't work.  So I look forward to the day when updates to these checks stop breaking my build.  Given Richard's comments, I don't think this check is the one.


https://reviews.llvm.org/D23719





More information about the cfe-commits mailing list