https://github.com/VigneshwarJ updated https://github.com/llvm/llvm-project/pull/185091
>From 74a4686bbe782dd503def11f1d649e11a4b4cf0e Mon Sep 17 00:00:00 2001 From: vigneshwar jayakumar <[email protected]> Date: Fri, 6 Mar 2026 13:19:43 -0600 Subject: [PATCH 1/2] [Clang] Fix EmitAggregateCopy assertion for non-trivially-copyable sret types Fix for buildbot crash on #183639 The UseTemp path in AggExprEmitter::withReturnValueSlot copies back via EmitAggregateCopy, which asserts that the type has a trivial copy/move constructor or assignment operator. Gate the DestASMismatch condition on isTriviallyCopyableType so that non-trivially-copyable types (e.g. std::exception_ptr) fall through to the addrspacecast path instead. Fix buildbot crash: https://lab.llvm.org/buildbot/#/builders/73/builds/19803 --- clang/lib/CodeGen/CGExprAgg.cpp | 13 +++---- .../CodeGenHIP/sret-nontrivial-copyable.hip | 34 +++++++++++++++++++ 2 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 clang/test/CodeGenHIP/sret-nontrivial-copyable.hip diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index 29a065d18c530..3a4291719da74 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -293,12 +293,13 @@ void AggExprEmitter::withReturnValueSlot( // destination is already in the alloca AS. unsigned SRetAS = CGF.getContext().getTargetAddressSpace( CGF.CGM.getASTAllocaAddressSpace()); - bool DestASMismatch = - !Dest.isIgnored() && Dest.getAddress() - .getBasePointer() - ->stripPointerCasts() - ->getType() - ->getPointerAddressSpace() != SRetAS; + bool DestASMismatch = !Dest.isIgnored() && + RetTy.isTriviallyCopyableType(CGF.getContext()) && + Dest.getAddress() + .getBasePointer() + ->stripPointerCasts() + ->getType() + ->getPointerAddressSpace() != SRetAS; bool UseTemp = Dest.isPotentiallyAliased() || Dest.requiresGCollection() || (RequiresDestruction && Dest.isIgnored()) || DestASMismatch; diff --git a/clang/test/CodeGenHIP/sret-nontrivial-copyable.hip b/clang/test/CodeGenHIP/sret-nontrivial-copyable.hip new file mode 100644 index 0000000000000..ee39104470fa1 --- /dev/null +++ b/clang/test/CodeGenHIP/sret-nontrivial-copyable.hip @@ -0,0 +1,34 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 6 +// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -emit-llvm -x c++ -std=c++2b %s -o - | FileCheck %s +// REQUIRES: amdgpu-registered-target + +// Verify that a non-trivially-copyable type returned via sret into a member +// field does not trigger an EmitAggregateCopy assertion. +// fix for a buildbot failure +struct NontrivialPtr { + void *p; + NontrivialPtr() noexcept; + NontrivialPtr(const NontrivialPtr &) noexcept; + NontrivialPtr &operator=(const NontrivialPtr &) noexcept; + ~NontrivialPtr() noexcept; +}; + +NontrivialPtr make() noexcept; + +struct Wrapper { + NontrivialPtr field; + Wrapper() noexcept; + virtual ~Wrapper() noexcept; +}; + +// CHECK-LABEL: define dso_local void @_ZN7WrapperC1Ev( +// CHECK-SAME: ptr noundef nonnull align 8 dereferenceable(16) [[THIS:%.*]]) unnamed_addr #[[ATTR0:[0-9]+]] align 2 { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT: [[THIS_ADDR:%.*]] = alloca ptr, align 8, addrspace(5) +// CHECK-NEXT: [[THIS_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[THIS_ADDR]] to ptr +// CHECK-NEXT: store ptr [[THIS]], ptr [[THIS_ADDR_ASCAST]], align 8 +// CHECK-NEXT: [[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR_ASCAST]], align 8 +// CHECK-NEXT: call void @_ZN7WrapperC2Ev(ptr noundef nonnull align 8 dereferenceable(16) [[THIS1]]) #[[ATTR2:[0-9]+]] +// CHECK-NEXT: ret void +// +Wrapper::Wrapper() noexcept : field(make()) {} >From 74c9258570643992f5ec82a393adc3a4149eb994 Mon Sep 17 00:00:00 2001 From: vigneshwar jayakumar <[email protected]> Date: Fri, 6 Mar 2026 13:56:17 -0600 Subject: [PATCH 2/2] test update --- clang/test/OpenMP/amdgcn_sret_ctor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/test/OpenMP/amdgcn_sret_ctor.cpp b/clang/test/OpenMP/amdgcn_sret_ctor.cpp index 8d2c035e23472..fc6f7c15eb5e6 100644 --- a/clang/test/OpenMP/amdgcn_sret_ctor.cpp +++ b/clang/test/OpenMP/amdgcn_sret_ctor.cpp @@ -16,11 +16,11 @@ E::E() noexcept : foo(s()) {} // CHECK-SAME: ptr noundef nonnull align 1 dereferenceable(1) [[THIS:%.*]]) unnamed_addr #[[ATTR0:[0-9]+]] align 2 { // CHECK-NEXT: [[ENTRY:.*:]] // CHECK-NEXT: [[THIS_ADDR:%.*]] = alloca ptr, align 8, addrspace(5) -// CHECK-NEXT: [[TMP:%.*]] = alloca [[STRUCT_S:%.*]], align 1, addrspace(5) // CHECK-NEXT: [[THIS_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[THIS_ADDR]] to ptr // CHECK-NEXT: store ptr [[THIS]], ptr [[THIS_ADDR_ASCAST]], align 8 // CHECK-NEXT: [[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR_ASCAST]], align 8 -// CHECK-NEXT: call void @_Z1sv(ptr addrspace(5) dead_on_unwind writable sret([[STRUCT_S]]) align 1 [[TMP]]) #[[ATTR2:[0-9]+]] +// CHECK-NEXT: [[THIS1_ASCAST:%.*]] = addrspacecast ptr [[THIS1]] to ptr addrspace(5) +// CHECK-NEXT: call void @_Z1sv(ptr addrspace(5) dead_on_unwind writable sret([[STRUCT_S:%.*]]) align 1 [[THIS1_ASCAST]]) #[[ATTR2:[0-9]+]] // CHECK-NEXT: ret void // // _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
