Skip to content

Commit 874e6a5

Browse files
authored
Teach isTriviallyCopyableType to return false when the type is an address-discriminated ptrauth type or a struct containing a field that has such a type
This fixes a crash in AggExprEmitter::EmitArrayInit that occurs when it tries to initialize an array of a struct with an address-discriminated ptrauth type field from a global. rdar://85173549
1 parent 8d98e2e commit 874e6a5

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

clang/lib/AST/Type.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,6 +2450,10 @@ bool QualType::isTriviallyCopyableType(const ASTContext &Context) const {
24502450
if (hasNonTrivialObjCLifetime())
24512451
return false;
24522452

2453+
PrimitiveCopyKind PCK = isNonTrivialToPrimitiveCopy();
2454+
if (PCK != PCK_Trivial && PCK != PCK_VolatileTrivial)
2455+
return false;
2456+
24532457
// C++11 [basic.types]p9 - See Core 2094
24542458
// Scalar types, trivially copyable class types, arrays of such types, and
24552459
// cv-qualified versions of these types are collectively

clang/test/CodeGen/ptrauth-in-c-struct.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ typedef struct {
2727
SA getSA(void);
2828
void calleeSA(SA);
2929

30+
int g0;
31+
3032
// CHECK: define void @test_copy_constructor_SA(%[[STRUCT_SA]]* %{{.*}})
3133
// CHECK: call void @__copy_constructor_8_8_t0w4_pa1_50_8(
3234

@@ -162,3 +164,21 @@ void test_copy_constructor_SI(SI *s) {
162164

163165
void test_parameter_SI(SI a) {
164166
}
167+
168+
// CHECK-LABEL: define void @test_array(
169+
// CHECK: %[[F1:.*]] = getelementptr inbounds %[[STRUCT_SA]], %[[STRUCT_SA]]* %{{.*}}, i32 0, i32 1
170+
// CHECK: %[[V0:.*]] = ptrtoint i32** %[[F1]] to i64
171+
// CHECK: %[[V1:.*]] = call i64 @llvm.ptrauth.blend(i64 %[[V0]], i64 50)
172+
// CHECK: %[[V2:.*]] = call i64 @llvm.ptrauth.sign(i64 ptrtoint (i32* @g0 to i64), i32 1, i64 %[[V1]])
173+
// CHECK: %[[V3:.*]] = inttoptr i64 %[[V2]] to i32*
174+
// CHECK: store i32* %[[V3]], i32** %[[F1]], align 8
175+
// CHECK: %[[F12:.*]] = getelementptr inbounds %[[STRUCT_SA]], %[[STRUCT_SA]]* %{{.*}}, i32 0, i32 1
176+
// CHECK: %[[V4:.*]] = ptrtoint i32** %[[F12]] to i64
177+
// CHECK: %[[V5:.*]] = call i64 @llvm.ptrauth.blend(i64 %[[V4]], i64 50)
178+
// CHECK: %[[V6:.*]] = call i64 @llvm.ptrauth.sign(i64 ptrtoint (i32* @g0 to i64), i32 1, i64 %[[V5]])
179+
// CHECK: %[[V7:.*]] = inttoptr i64 %[[V6]] to i32*
180+
// CHECK: store i32* %[[V7]], i32** %[[F12]], align 8
181+
182+
void test_array(void) {
183+
const SA a[] = {{0, &g0}, {1, &g0}};
184+
}

0 commit comments

Comments
 (0)