[libcxx-commits] [libcxx] [libc++] "Always" include_next for non C++ path in stdatomic.h (PR #178463)
Walter Lee via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Jan 29 10:41:21 PST 2026
https://github.com/googlewalt updated https://github.com/llvm/llvm-project/pull/178463
>From 195b82164d17344c4ce4fbf051feb817eaf5cf65 Mon Sep 17 00:00:00 2001
From: Walter Lee <waltl at google.com>
Date: Wed, 28 Jan 2026 11:33:18 -0500
Subject: [PATCH 1/5] [libcpp] Unconditionally include_next in stdatomic.h
"#ifdef _cplusplus", so _LIBCPP_COMPILER_CLANG_BASED is no longer set
for C compiles. This causes a regression internally, where C compiles
no longer get the C header when it includes stdatomic.h.
C++ stdlib headers "shouldn't" be on the search patch for C compile,
but we do and so do lots of other people, so libc++ tends to support
that. The include_next for a C compile should be unconditional, not
conditional upon being Clang.
---
libcxx/include/__cxx03/stdatomic.h | 2 +-
libcxx/include/stdatomic.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/libcxx/include/__cxx03/stdatomic.h b/libcxx/include/__cxx03/stdatomic.h
index 78bb745303c1a..30378e5abef8a 100644
--- a/libcxx/include/__cxx03/stdatomic.h
+++ b/libcxx/include/__cxx03/stdatomic.h
@@ -220,7 +220,7 @@ using std::atomic_store_explicit _LIBCPP_USING_IF_EXISTS;
using std::atomic_signal_fence _LIBCPP_USING_IF_EXISTS;
using std::atomic_thread_fence _LIBCPP_USING_IF_EXISTS;
-#elif defined(_LIBCPP_COMPILER_CLANG_BASED)
+#else
// 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>
diff --git a/libcxx/include/stdatomic.h b/libcxx/include/stdatomic.h
index 2991030eee456..aeb4442898c09 100644
--- a/libcxx/include/stdatomic.h
+++ b/libcxx/include/stdatomic.h
@@ -231,7 +231,7 @@ using std::atomic_store_explicit _LIBCPP_USING_IF_EXISTS;
using std::atomic_signal_fence _LIBCPP_USING_IF_EXISTS;
using std::atomic_thread_fence _LIBCPP_USING_IF_EXISTS;
-# elif defined(_LIBCPP_COMPILER_CLANG_BASED)
+# else
// 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>
>From 3004b4d67ea30eaff10e368becbcf97caf491da5 Mon Sep 17 00:00:00 2001
From: Walter Lee <waltl at google.com>
Date: Wed, 28 Jan 2026 12:03:09 -0500
Subject: [PATCH 2/5] Fix else conditional to exclude C++ for non-clang
compilers
---
libcxx/include/__cxx03/stdatomic.h | 2 +-
libcxx/include/stdatomic.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/libcxx/include/__cxx03/stdatomic.h b/libcxx/include/__cxx03/stdatomic.h
index 30378e5abef8a..4aa1ad406bcf3 100644
--- a/libcxx/include/__cxx03/stdatomic.h
+++ b/libcxx/include/__cxx03/stdatomic.h
@@ -220,7 +220,7 @@ using std::atomic_store_explicit _LIBCPP_USING_IF_EXISTS;
using std::atomic_signal_fence _LIBCPP_USING_IF_EXISTS;
using std::atomic_thread_fence _LIBCPP_USING_IF_EXISTS;
-#else
+#elif !defined(__cplusplus) || defined(_LIBCPP_COMPILER_CLANG_BASED)
// 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>
diff --git a/libcxx/include/stdatomic.h b/libcxx/include/stdatomic.h
index aeb4442898c09..e7b787560ddc4 100644
--- a/libcxx/include/stdatomic.h
+++ b/libcxx/include/stdatomic.h
@@ -231,7 +231,7 @@ using std::atomic_store_explicit _LIBCPP_USING_IF_EXISTS;
using std::atomic_signal_fence _LIBCPP_USING_IF_EXISTS;
using std::atomic_thread_fence _LIBCPP_USING_IF_EXISTS;
-# else
+# elif !defined(__cplusplus) || defined(_LIBCPP_COMPILER_CLANG_BASED)
// 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>
>From da303c1720fd97f24218c68bedb20adb8a00f615 Mon Sep 17 00:00:00 2001
From: Walter Lee <waltl at google.com>
Date: Wed, 28 Jan 2026 12:21:51 -0500
Subject: [PATCH 3/5] Revert __cxx03 changes
---
libcxx/include/__cxx03/stdatomic.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libcxx/include/__cxx03/stdatomic.h b/libcxx/include/__cxx03/stdatomic.h
index 4aa1ad406bcf3..30378e5abef8a 100644
--- a/libcxx/include/__cxx03/stdatomic.h
+++ b/libcxx/include/__cxx03/stdatomic.h
@@ -220,7 +220,7 @@ using std::atomic_store_explicit _LIBCPP_USING_IF_EXISTS;
using std::atomic_signal_fence _LIBCPP_USING_IF_EXISTS;
using std::atomic_thread_fence _LIBCPP_USING_IF_EXISTS;
-#elif !defined(__cplusplus) || defined(_LIBCPP_COMPILER_CLANG_BASED)
+#else
// 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>
>From 47c2df3e324d750a0e0d11d42fe2a26758089cd4 Mon Sep 17 00:00:00 2001
From: Walter Lee <waltl at google.com>
Date: Wed, 28 Jan 2026 12:23:00 -0500
Subject: [PATCH 4/5] *Actually* revert _cxx03 changes
---
libcxx/include/__cxx03/stdatomic.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libcxx/include/__cxx03/stdatomic.h b/libcxx/include/__cxx03/stdatomic.h
index 30378e5abef8a..78bb745303c1a 100644
--- a/libcxx/include/__cxx03/stdatomic.h
+++ b/libcxx/include/__cxx03/stdatomic.h
@@ -220,7 +220,7 @@ using std::atomic_store_explicit _LIBCPP_USING_IF_EXISTS;
using std::atomic_signal_fence _LIBCPP_USING_IF_EXISTS;
using std::atomic_thread_fence _LIBCPP_USING_IF_EXISTS;
-#else
+#elif defined(_LIBCPP_COMPILER_CLANG_BASED)
// 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>
>From f2e9ff9fa734d126f5e5f434b05825c37eecb10d Mon Sep 17 00:00:00 2001
From: Walter Lee <waltl at google.com>
Date: Thu, 29 Jan 2026 13:41:00 -0500
Subject: [PATCH 5/5] Add test
---
.../include_stdatomic_as_c.sh.cpp | 30 +++++++++++++++++++
1 file changed, 30 insertions(+)
create mode 100644 libcxx/test/extensions/libcxx/depr/depr.c.headers/include_stdatomic_as_c.sh.cpp
diff --git a/libcxx/test/extensions/libcxx/depr/depr.c.headers/include_stdatomic_as_c.sh.cpp b/libcxx/test/extensions/libcxx/depr/depr.c.headers/include_stdatomic_as_c.sh.cpp
new file mode 100644
index 0000000000000..31ad5c9053675
--- /dev/null
+++ b/libcxx/test/extensions/libcxx/depr/depr.c.headers/include_stdatomic_as_c.sh.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// We're building as C, so this test doesn't work when building with modules.
+// UNSUPPORTED: clang-modules-build
+
+// GCC complains about unrecognized arguments because we're compiling the
+// file as C, but we're passing C++ flags on the command-line.
+// UNSUPPORTED: gcc
+
+// Test that stdatomic.h gets the C header with its definitions.
+
+// NOTE: It's not common or recommended to have libc++ in the header search
+// path when compiling C files, but it does happen often enough.
+
+// RUN: %{cxx} -c -xc %s -fsyntax-only %{flags} %{compile_flags} -std=c99
+
+#include <stdatomic.h>
+
+int main(int argc, char** argv) {
+ (void)argc;
+ (void)argv;
+ [[maybe_unused]] atomic_bool x;
+ return 0;
+}
More information about the libcxx-commits
mailing list