Author: Igor Zhukov Date: 2022-07-25T19:00:29+02:00 New Revision: ba49d39b20cc5358da28af2ac82bd336028780bc
URL: https://github.com/llvm/llvm-project/commit/ba49d39b20cc5358da28af2ac82bd336028780bc DIFF: https://github.com/llvm/llvm-project/commit/ba49d39b20cc5358da28af2ac82bd336028780bc.diff LOG: 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 Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Headers/stdatomic.h Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 317fd250b1933..ab2f6387492b7 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -196,6 +196,8 @@ Bug Fixes used in comparison operators. Fixes `Issue 56560 <https://github.com/llvm/llvm-project/issues/56560>`_. - Fix that ``if consteval`` could evaluate to ``true`` at runtime because it was incorrectly constant folded. Fixes `Issue 55638 <https://github.com/llvm/llvm-project/issues/55638>`_. +- Fixed incompatibility of Clang's ``<stdatomic.h>`` with MSVC ``<atomic>``. + Fixes `MSVC STL Issue 2862 <https://github.com/microsoft/STL/issues/2862>`_. Improvements to Clang's diagnostics ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Headers/stdatomic.h b/clang/lib/Headers/stdatomic.h index 3a0b9cc056bef..318c7ca56e418 100644 --- a/clang/lib/Headers/stdatomic.h +++ b/clang/lib/Headers/stdatomic.h @@ -17,7 +17,8 @@ * explicitly disallows `stdatomic.h` in the C mode via an `#error`. Fallback * to the clang resource header until that is fully supported. */ -#if __STDC_HOSTED__ && __has_include_next(<stdatomic.h>) && !defined(_MSC_VER) +#if __STDC_HOSTED__ && \ + __has_include_next(<stdatomic.h>) && !(defined(_MSC_VER) && !defined(__cplusplus)) # include_next <stdatomic.h> #else _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits