Skip to content

Commit 6c57bab

Browse files
aeubankststellar
authored andcommitted
[clang] Don't assert in EmitAggregateCopy on trivial_abi types
Fixes PR42961. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D97872 (cherry picked from commit c8227f0)
1 parent fa21c5d commit 6c57bab

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

clang/lib/CodeGen/CGExprAgg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2056,7 +2056,7 @@ void CodeGenFunction::EmitAggregateCopy(LValue Dest, LValue Src, QualType Ty,
20562056
Record->hasTrivialCopyAssignment() ||
20572057
Record->hasTrivialMoveConstructor() ||
20582058
Record->hasTrivialMoveAssignment() ||
2059-
Record->isUnion()) &&
2059+
Record->hasAttr<TrivialABIAttr>() || Record->isUnion()) &&
20602060
"Trying to aggregate-copy a type without a trivial copy/move "
20612061
"constructor or assignment operator");
20622062
// Ignore empty classes in C++.

clang/test/CodeGenCXX/trivial_abi.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,21 @@ void calleeExceptionLarge(Large, Large);
262262
void testExceptionLarge() {
263263
calleeExceptionLarge(Large(), Large());
264264
}
265+
266+
// PR42961
267+
268+
// CHECK: define{{.*}} @"_ZN3$_08__invokeEv"()
269+
// CHECK: %[[RETVAL:.*]] = alloca %[[STRUCT_SMALL]], align 8
270+
// CHECK: %[[COERCE:.*]] = alloca %[[STRUCT_SMALL]], align 8
271+
// CHECK: %[[CALL:.*]] = call{{.*}} @"_ZNK3$_0clEv"
272+
// CHECK: %[[COERCEDIVE:.*]] = getelementptr{{.*}} %[[COERCE]]
273+
// CHECK: %[[COERCEVALIP:.*]] = inttoptr{{.*}} %[[CALL]]
274+
// CHECK: %[[RETVALP:.*]] = bitcast %[[STRUCT_SMALL]]* %[[RETVAL]]
275+
// CHECK: %[[COERCEP:.*]] = bitcast %[[STRUCT_SMALL]]* %[[COERCE]]
276+
// CHECK: call {{.*}}memcpy{{.*}} %[[RETVALP]]{{.*}} %[[COERCEP]]
277+
// CHECK: %[[COERCEDIVE1:.*]] = getelementptr{{.*}} %[[RETVAL]]
278+
// CHECK: %[[TMP:.*]] = load{{.*}} %[[COERCEDIVE1]]
279+
// CHECK: %[[COERCEVALPI:.*]] = ptrtoint{{.*}} %[[TMP]]
280+
// CHECK: ret{{.*}} %[[COERCEVALPI]]
281+
282+
Small (*fp)() = []() -> Small { return Small(); };

0 commit comments

Comments
 (0)