[all-commits] [llvm/llvm-project] d5194b: [Clang] define memory scopes as a builtin enum

Sameer Sahasrabuddhe via All-commits all-commits at lists.llvm.org
Mon Mar 9 05:38:08 PDT 2026


  Branch: refs/heads/users/ssahasra/memory-scope-enum
  Home:   https://github.com/llvm/llvm-project
  Commit: d5194b55562690d9f426c0746b2730e67e8ce333
      https://github.com/llvm/llvm-project/commit/d5194b55562690d9f426c0746b2730e67e8ce333
  Author: Sameer Sahasrabuddhe <sameer.sahasrabuddhe at amd.com>
  Date:   2026-03-09 (Mon, 09 Mar 2026)

  Changed paths:
    M clang/include/clang/AST/ASTContext.h
    M clang/include/clang/AST/DeclID.h
    M clang/include/clang/Basic/DiagnosticSemaKinds.td
    M clang/lib/AST/ASTContext.cpp
    M clang/lib/Frontend/InitPreprocessor.cpp
    M clang/lib/Sema/SemaChecking.cpp
    M clang/lib/Sema/SemaLookup.cpp
    M clang/lib/Serialization/ASTReader.cpp
    M clang/lib/Serialization/ASTWriter.cpp
    M clang/test/Preprocessor/init-aarch64.c
    M clang/test/Preprocessor/init-loongarch.c
    M clang/test/Preprocessor/init.c
    A clang/test/Sema/builtin-memory-scope-conflict.c
    A clang/test/Sema/builtin-memory-scope-shadowing.c
    A clang/test/Sema/builtin-memory-scope.c
    M clang/test/Sema/scoped-atomic-ops.c
    A clang/test/Sema/scoped-atomic-scope-deprecation.c
    M clang/test/SemaOpenCL/atomic-ops.cl

  Log Message:
  -----------
  [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



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list