[all-commits] [llvm/llvm-project] ba49d3: Use `<stdatomic.h>` with MSVC and C++

Igor Zhukov via All-commits all-commits at lists.llvm.org
Mon Jul 25 10:00:42 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: ba49d39b20cc5358da28af2ac82bd336028780bc
      https://github.com/llvm/llvm-project/commit/ba49d39b20cc5358da28af2ac82bd336028780bc
  Author: Igor Zhukov <fsb4000 at yandex.ru>
  Date:   2022-07-25 (Mon, 25 Jul 2022)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/lib/Headers/stdatomic.h

  Log Message:
  -----------
  Use `<stdatomic.h>` with MSVC and C++

and use fallback only for C.

It fixes the isssue with clang-cl:

```
#include <stdatomic.h>
#include <stdbool.h>
#ifdef __cplusplus
#include <atomic>
using namespace std;
#endif

int main() {
    atomic_bool b = true;
}
```

```
$ clang-cl /TC main.cpp
# works
```
```
$ clang-cl /TP /std:c++20 main.cpp

stdatomic.h(70,6): error: conflicting types for 'atomic_thread_fence'
void atomic_thread_fence(memory_order);
     ^
atomic(166,24): note: previous definition is here
extern "C" inline void atomic_thread_fence(const memory_order _Order) noexcept {

...

fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
```
Many errors but
`<stdatomic.h>` has many macros to built-in functions.
```
#define atomic_thread_fence(order) __c11_atomic_thread_fence(order)
```
and MSVC `<atomic>` has real functions.
and the built-in functions are redefined.

Reviewed By: #libc, aaron.ballman, Mordante

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




More information about the All-commits mailing list