[clang] [Clang] Fix invalid sret addrspacecast for placement new on HIP (PR #183639)
Vigneshwar Jayakumar via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 3 15:08:38 PST 2026
================
@@ -286,8 +286,15 @@ 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.
- bool UseTemp = Dest.isPotentiallyAliased() || Dest.requiresGCollection() ||
- (RequiresDestruction && Dest.isIgnored());
+ //
+ // 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.
+ bool UseTemp =
+ Dest.isPotentiallyAliased() || Dest.requiresGCollection() ||
+ (RequiresDestruction && Dest.isIgnored()) ||
+ (!Dest.isIgnored() && Dest.getAddress().getAddressSpace() !=
----------------
VigneshwarJ wrote:
When Dest is ignored, there's no destination pointer to be incorrectly addrspacecast'd, and the existing path handles it correctly: RetAddr is passed as invalid, EmitCall detects ReturnValue.isNull() and creates its own temporary in the alloca AS. Also, we need the check because getAddress() on an ignored slot returns an invalid Address
https://github.com/llvm/llvm-project/pull/183639
More information about the cfe-commits
mailing list