Skip to content

clang: Read the address space from the ABIArgInfo #138865

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

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented May 7, 2025

Do not assume it's the alloca address space, we have an explicit
address space to use for the argument already. Also use the original
value's type instead of assuming DefaultAS.

@llvmbot
Copy link
Member

llvmbot commented May 7, 2025

@llvm/pr-subscribers-clang
@llvm/pr-subscribers-backend-amdgpu

@llvm/pr-subscribers-clang-codegen

Author: Matt Arsenault (arsenm)

Changes

Do not assume it's the alloca address space, we have an explicit
address space to use for the argument already. Also use the original
value's type instead of assuming DefaultAS.


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

1 Files Affected:

  • (modified) clang/lib/CodeGen/CGCall.cpp (+4-4)
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 1404bdfd69647..db8820a8c517e 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -5384,16 +5384,16 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
         if (!NeedCopy) {
           // Skip the extra memcpy call.
           llvm::Value *V = getAsNaturalPointerTo(Addr, I->Ty);
-          auto *T = llvm::PointerType::get(
-              CGM.getLLVMContext(), CGM.getDataLayout().getAllocaAddrSpace());
+          auto *T = llvm::PointerType::get(CGM.getLLVMContext(),
+                                           ArgInfo.getIndirectAddrSpace());
 
           // FIXME: This should not depend on the language address spaces, and
           // only the contextual values. If the address space mismatches, see if
           // we can look through a cast to a compatible address space value,
           // otherwise emit a copy.
           llvm::Value *Val = getTargetHooks().performAddrSpaceCast(
-              *this, V, LangAS::Default, CGM.getASTAllocaAddressSpace(), T,
-              true);
+              *this, V, I->Ty.getAddressSpace(), CGM.getASTAllocaAddressSpace(),
+              T, true);
           if (ArgHasMaybeUndefAttr)
             Val = Builder.CreateFreeze(Val);
           IRCallArgs[FirstIRArg] = Val;

@arsenm arsenm marked this pull request as ready for review May 7, 2025 13:16
@llvmbot llvmbot added the clang Clang issues not falling into any other category label May 7, 2025
@arsenm arsenm force-pushed the users/arsenm/clang/use-getIndirectAddrSpace-not-getAllocaAddrSpace branch from 2e920e9 to d1a11ed Compare May 7, 2025 18:35
@arsenm arsenm force-pushed the users/arsenm/clang/fix-special-casing-opencl-in-call-lowering branch from e48afb5 to 8593287 Compare May 7, 2025 18:35
Copy link
Member

@Artem-B Artem-B left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM w/ a comment nit.

@arsenm arsenm force-pushed the users/arsenm/clang/fix-special-casing-opencl-in-call-lowering branch from 8593287 to f0dd54a Compare May 8, 2025 05:53
@arsenm arsenm force-pushed the users/arsenm/clang/use-getIndirectAddrSpace-not-getAllocaAddrSpace branch from d1a11ed to 4a1cda9 Compare May 8, 2025 05:54
Copy link
Contributor Author

arsenm commented May 9, 2025

Merge activity

  • May 9, 8:13 AM EDT: A user started a stack merge that includes this pull request via Graphite.
  • May 9, 8:16 AM EDT: Graphite rebased this pull request as part of a merge.
  • May 9, 8:19 AM EDT: @arsenm merged this pull request with Graphite.

@arsenm arsenm force-pushed the users/arsenm/clang/fix-special-casing-opencl-in-call-lowering branch from f0dd54a to 4a054e4 Compare May 9, 2025 12:14
Base automatically changed from users/arsenm/clang/fix-special-casing-opencl-in-call-lowering to main May 9, 2025 12:15
Do not assume it's the alloca address space, we have an explicit
address space to use for the argument already. Also use the original
value's type instead of assuming DefaultAS.
@arsenm arsenm force-pushed the users/arsenm/clang/use-getIndirectAddrSpace-not-getAllocaAddrSpace branch from 4a1cda9 to d7d6cf5 Compare May 9, 2025 12:16
@arsenm arsenm merged commit e8898a6 into main May 9, 2025
6 of 10 checks passed
@arsenm arsenm deleted the users/arsenm/clang/use-getIndirectAddrSpace-not-getAllocaAddrSpace branch May 9, 2025 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AMDGPU clang:codegen IR generation bugs: mangling, exceptions, etc. clang Clang issues not falling into any other category OpenCL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants