Skip to content

Conversation

@Maetveis
Copy link
Contributor

Replace Context.getLangASForBuiltinAddressSpace(1) with getLangASFromTargetAS(1) in SemaDecl.cpp to determine the language address space for WebAssembly tables.

getLangASForBuiltinAddressSpace is meant to map from the numeric values used in Builtins.def to language address spaces in the case where different language modes have similar address spaces (usually all mapping to the same backend i.e. LLVM aspace). For example for the AMDGPU target the numeric value 0 in BuiltinsAMDGPU.def is mapped to LangAS::Default for CUDA/HIP and LangAS::opencl_generic for OpenCL.

This usage in SemaDecl.cpp is not this case.
The webassembly target does not override getOpenCLBuiltinAddressSpace or getCUDABuiltinAddressSpace, so we end up calling getLangASFromTargetAS indirectly before this patch anyway.

Replace `Context.getLangASForBuiltinAddressSpace(1)` with
`getLangASFromTargetAS(1)` in `SemaDecl.cpp` to determine the language
address space for WebAssembly tables.

`getLangASForBuiltinAddressSpace` is meant to map from the numeric values
used in Builtins<Target>.def to language address spaces in the case
where different language modes have similar address spaces (usually
all mapping to the same backend i.e. LLVM aspace).
For example for the AMDGPU target the numeric value 0 in BuiltinsAMDGPU.def
is mapped to LangAS::Default for CUDA/HIP and LangAS::opencl_generic for
OpenCL.

This usage in SemaDecl.cpp is not this case.
The webassembly target does not override `getOpenCLBuiltinAddressSpace`
or `getCUDABuiltinAddressSpace`, so we end up calling `getLangASFromTargetAS`
indirectly before this patch anyway.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Dec 19, 2025
@llvmbot
Copy link
Member

llvmbot commented Dec 19, 2025

@llvm/pr-subscribers-clang

Author: Mészáros Gergely (Maetveis)

Changes

Replace Context.getLangASForBuiltinAddressSpace(1) with getLangASFromTargetAS(1) in SemaDecl.cpp to determine the language address space for WebAssembly tables.

getLangASForBuiltinAddressSpace is meant to map from the numeric values used in Builtins<Target>.def to language address spaces in the case where different language modes have similar address spaces (usually all mapping to the same backend i.e. LLVM aspace). For example for the AMDGPU target the numeric value 0 in BuiltinsAMDGPU.def is mapped to LangAS::Default for CUDA/HIP and LangAS::opencl_generic for OpenCL.

This usage in SemaDecl.cpp is not this case.
The webassembly target does not override getOpenCLBuiltinAddressSpace or getCUDABuiltinAddressSpace, so we end up calling getLangASFromTargetAS indirectly before this patch anyway.


Full diff: https://github.com/llvm/llvm-project/pull/173010.diff

1 Files Affected:

  • (modified) clang/lib/Sema/SemaDecl.cpp (+2-2)
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 72039cc164d88..248ec14fb6c25 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8189,8 +8189,8 @@ NamedDecl *Sema::ActOnVariableDeclarator(
   if (const auto *ATy = dyn_cast<ArrayType>(NewVD->getType())) {
     if (ATy && ATy->getElementType().isWebAssemblyReferenceType() &&
         !NewVD->hasLocalStorage()) {
-      QualType Type = Context.getAddrSpaceQualType(
-          NewVD->getType(), Context.getLangASForBuiltinAddressSpace(1));
+      QualType Type = Context.getAddrSpaceQualType(NewVD->getType(),
+                                                   getLangASFromTargetAS(1));
       NewVD->setType(Type);
     }
   }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants