[libcxx-commits] [PATCH] D131435: [libcxx] Make stdatomic.h work when included from a C source file

Shoaib Meenai via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Aug 8 13:33:02 PDT 2022


smeenai created this revision.
Herald added a project: All.
smeenai requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

If a C source file includes the libc++ stdatomic.h, compilation will
break because (a) the C++ standard check will fail (which is expected),
and (b) `_LIBCPP_COMPILER_CLANG_BASED` won't be defined because the
logic defining it in `__config` is guarded by a `__cplusplus` check, so
we'll end up with a blank header. Check for `__clang__` directly, which
is equivalent, to make the second check pass even in a C context when
you're using Clang.

In an ideal world, a C source file wouldn't be including the libc++
header directory in its search path, so we'd never have this issue.
Unfortunately, certain build environments make this hard to guarantee,
and in this case it's easy to tweak this header to make it work in a C
context, so I'm hoping this is acceptable.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131435

Files:
  libcxx/include/stdatomic.h


Index: libcxx/include/stdatomic.h
===================================================================
--- libcxx/include/stdatomic.h
+++ libcxx/include/stdatomic.h
@@ -220,7 +220,7 @@
 using std::atomic_signal_fence _LIBCPP_USING_IF_EXISTS;
 using std::atomic_thread_fence _LIBCPP_USING_IF_EXISTS;
 
-#elif defined(_LIBCPP_COMPILER_CLANG_BASED)
+#elif defined(__clang__)
 
 // Before C++23, we include the next <stdatomic.h> on the path to avoid hijacking
 // the header. We do this because Clang has historically shipped a <stdatomic.h>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131435.450924.patch
Type: text/x-patch
Size: 538 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220808/6ab6bc92/attachment.bin>


More information about the libcxx-commits mailing list