[all-commits] [llvm/llvm-project] afec0f: [libcxx] Make stdatomic.h work when included from ...

Gergely Nagy via All-commits all-commits at lists.llvm.org
Tue Sep 27 10:13:42 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: afec0f0ec38a72bcc6a697c1cefb1dac0bbd02fb
      https://github.com/llvm/llvm-project/commit/afec0f0ec38a72bcc6a697c1cefb1dac0bbd02fb
  Author: Gergely Nagy <ngg at ngg.hu>
  Date:   2022-09-27 (Tue, 27 Sep 2022)

  Changed paths:
    M libcxx/include/__config
    M libcxx/include/stdatomic.h
    M libcxx/test/libcxx/include_as_c.sh.cpp

  Log Message:
  -----------
  [libcxx] Make stdatomic.h work when included from a C source file

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. Move the detection logic outside of
the `__cplusplus` check to make the second check pass even in a C context
when you're using Clang. Note that `_LIBCPP_STD_VER` is not defined when
in C mode, hence stdatomic.h needs to check if in C++ mode before using
that macro to avoid a warning.

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.

Fixes https://github.com/llvm/llvm-project/issues/57710.

Differential Revision: https://reviews.llvm.org/D134591




More information about the All-commits mailing list