llvm-project
bd31d4dc - [Clang] define memory scopes as a builtin enum

Commit
170 days ago
[Clang] define memory scopes as a builtin enum Clang currently represents memory scopes as pre-defined preprocessor macros that evaluate to integers. But so far, there are three sets of conflicting scopes: "common" clang scopes, HIP scopes and OpenCL scopes. These sets use the same integers in different orders, making it impossible to validate their use. A better approach is to represent these scopes as enum types, so that the integer values become less significant. Sema can now validate the scope argument by its type instead. Both C and C++ define an enum for memory_order, but there is no standard enum for memory_scope. This change introduces a Clang-specific enum "memory_scope". The pre-defined macros are now mapped to this enum. Later changes can add similar enums for other languages. enum __memory_scope { __memory_scope_system, __memory_scope_device, __memory_scope_workgroup, __memory_scope_wavefront, __memory_scope_singlethread, __memory_scope_cluster }; Note that since this is not a standard enum, it cannot be introduced via stdatomic.h or other headers. Instead Sema builds this enum on demand when it sees an identifier that matches one of the enumerators. This ensures that the enum is injected in the AST only if it is used. Otherwise, it will show up in every program being compiled, which is noticeable in a number of test failures that were not expecting this enum. For a gradual transition, Sema will continue to accept integer values for the "__scoped_atomic_*" builtins, but issue a warning in favour of the new enums. This change will only be visible to clients that use PCH files or clients like hip-rtc that store pre-processed files that are then passed to a newer compiler in the application's environment. Assisted-By: Claude Sonnet 4.5
Author
Committer
Parents
Loading