[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.
This commit is contained in:
Walter Lee 2026-01-30 10:01:51 -05:00 committed by GitHub
parent d1e2ddf997
commit 09f8f22a64
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 1 deletions

View File

@ -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 <stdatomic.h> on the path to avoid hijacking
// the header. We do this because Clang has historically shipped a <stdatomic.h>

View File

@ -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;
}