Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support C11 atomics on compilers that don't define __GNUC__ if they declare an extension or C11 atomic support. #19840

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions upb/port/def.inc
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,18 @@ Error, UINTPTR_MAX is undefined
#define UPB_LONGJMP(buf, val) longjmp(buf, val)
#endif

#ifdef __GNUC__
#if ((__STDC_VERSION__ >= 201112L) && !defined(__STDC_NO_ATOMICS__))
#define UPB_USE_C11_ATOMICS
#elif defined(__has_extension)
#if __has_extension(c_atomic)
#define UPB_USE_C11_ATOMICS
#endif
#elif defined(__GNUC__)
// GCC supported atomics as an extension before it supported __has_extension
#define UPB_USE_C11_ATOMICS
#endif

#if defined(UPB_USE_C11_ATOMICS)
#define UPB_ATOMIC(T) _Atomic(T)
#else
#define UPB_ATOMIC(T) T
Expand Down Expand Up @@ -311,7 +321,7 @@ Error, UINTPTR_MAX is undefined
*/

/* Due to preprocessor limitations, the conditional logic for setting
* UPN_CLANG_ASAN below cannot be consolidated into a portable one-liner.
* UPB_CLANG_ASAN below cannot be consolidated into a portable one-liner.
* See https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fattribute.html.
*/
#if defined(__has_feature)
Expand Down
Loading