From 09f8f22a6451a4d88115cde4d6f19ffd1855a5d5 Mon Sep 17 00:00:00 2001 From: Walter Lee <49250218+googlewalt@users.noreply.github.com> Date: Fri, 30 Jan 2026 10:01:51 -0500 Subject: [PATCH] [libc++] "Always" include_next for non C++ path in stdatomic.h (#178463) In https://github.com/llvm/llvm-project/pull/176903, `#include <__configuration/compiler.h>` is moved into the `#ifdef _cplusplus` clause, so `_LIBCPP_COMPILER_CLANG_BASED` is no longer set for C compiles. This causes a regression internally, where when C compiles includes stdatomic.h, they no longer get the corresponding C header. 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. This include_next for a C compile should be unconditional, not conditional upon being Clang. --- libcxx/include/stdatomic.h | 2 +- .../include_stdatomic_as_c.sh.cpp | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 libcxx/test/extensions/libcxx/depr/depr.c.headers/include_stdatomic_as_c.sh.cpp diff --git a/libcxx/include/stdatomic.h b/libcxx/include/stdatomic.h index 2991030eee45..e7b787560ddc 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) +# elif !defined(__cplusplus) || defined(_LIBCPP_COMPILER_CLANG_BASED) // Before C++23, we include the next on the path to avoid hijacking // the header. We do this because Clang has historically shipped a 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 000000000000..31ad5c905367 --- /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 + +int main(int argc, char** argv) { + (void)argc; + (void)argv; + [[maybe_unused]] atomic_bool x; + return 0; +}