[clang] [Clang] Fix invalid sret addrspacecast for placement new on HIP (PR #183639)

Vigneshwar Jayakumar via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 5 19:12:07 PST 2026


================
@@ -286,8 +286,24 @@ void AggExprEmitter::withReturnValueSlot(
   // We need to always provide our own temporary if destruction is required.
   // Otherwise, EmitCall will emit its own, notice that it's "unused", and end
   // its lifetime before we have the chance to emit a proper destructor call.
+  //
+  // We also need a temporary if the destination is in a different address space
+  // from the alloca AS, to avoid an invalid addrspacecast on the sret pointer.
+  // Look through addrspacecasts to avoid unnecessary temps when the
+  // destination is already in the alloca AS.
+  bool DestASMismatch = false;
+  if (!Dest.isIgnored()) {
+    unsigned SRetAS = CGF.getContext().getTargetAddressSpace(
+        CGF.CGM.getASTAllocaAddressSpace());
+    unsigned DestAS = Dest.getAddress()
+                          .getBasePointer()
+                          ->stripPointerCasts()
+                          ->getType()
+                          ->getPointerAddressSpace();
+    DestASMismatch = DestAS != SRetAS;
----------------
VigneshwarJ wrote:

resolved it by doing the cast here

https://github.com/llvm/llvm-project/pull/183639


More information about the cfe-commits mailing list