Skip to content

Commit

Permalink
[clang] Define ATOMIC_FLAG_INIT correctly for C++. (#97534)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisnc authored Jul 24, 2024
1 parent 550b83d commit 4bb3a1e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ Improvements to Coverage Mapping
Bug Fixes in This Version
-------------------------

- Fixed the definition of ``ATOMIC_FLAG_INIT`` in ``<stdatomic.h>`` so it can
be used in C++.

Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Headers/stdatomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,11 @@ typedef _Atomic(uintmax_t) atomic_uintmax_t;

typedef struct atomic_flag { atomic_bool _Value; } atomic_flag;

#ifdef __cplusplus
#define ATOMIC_FLAG_INIT {false}
#else
#define ATOMIC_FLAG_INIT { 0 }
#endif

/* These should be provided by the libc implementation. */
#ifdef __cplusplus
Expand Down
5 changes: 5 additions & 0 deletions clang/test/Headers/stdatomic.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// RUN: %clang_cc1 -std=c11 -E %s | FileCheck %s
// RUN: %clang_cc1 -std=c11 -fms-compatibility -E %s | FileCheck %s
// RUN: %clang_cc1 -std=c11 %s -verify
// RUN: %clang_cc1 -x c++ -std=c++11 %s -verify
// expected-no-diagnostics
#include <stdatomic.h>

int bool_lock_free = ATOMIC_BOOL_LOCK_FREE;
Expand Down Expand Up @@ -31,3 +34,5 @@ int llong_lock_free = ATOMIC_LLONG_LOCK_FREE;

int pointer_lock_free = ATOMIC_POINTER_LOCK_FREE;
// CHECK: pointer_lock_free = {{ *[012] *;}}

atomic_flag f = ATOMIC_FLAG_INIT;

0 comments on commit 4bb3a1e

Please sign in to comment.