[clang] [Clang] define memory scopes as a builtin enum (PR #185408)
Sameer Sahasrabuddhe via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 26 18:18:08 PDT 2026
================
@@ -874,12 +874,12 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
Builder.defineMacro("__ATOMIC_SEQ_CST", "5");
// Define macros for the clang atomic scopes.
- Builder.defineMacro("__MEMORY_SCOPE_SYSTEM", "0");
- Builder.defineMacro("__MEMORY_SCOPE_DEVICE", "1");
- Builder.defineMacro("__MEMORY_SCOPE_WRKGRP", "2");
- Builder.defineMacro("__MEMORY_SCOPE_WVFRNT", "3");
- Builder.defineMacro("__MEMORY_SCOPE_SINGLE", "4");
- Builder.defineMacro("__MEMORY_SCOPE_CLUSTR", "5");
+ Builder.defineMacro("__MEMORY_SCOPE_SYSTEM", "__memory_scope_system");
----------------
ssahasra wrote:
> Should the same be done for the orderings?
Orderings are defined by the C11 and C++11 standards, and everyone else just follows the same numbering, so there is no issue there.
> Also is there a reason these were implemented with defineMacro, instead of requiring you to include a builtin header of some sort?
I think #72280 was merely following the pattern set by the orderings. It could have been a header, but having it in the preprocessor means that the Clang scoped extension of the GNU atomics "just works".
https://github.com/llvm/llvm-project/pull/185408
More information about the cfe-commits
mailing list