Skip to content

Commit 89ba0db

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 (#5072)
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 (cherry picked from commit 997b179) Conflicts: clang/test/CodeGen/ptrauth-in-c-struct.c
1 parent 86d0ea6 commit 89ba0db

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
@@ -2467,6 +2467,10 @@ bool QualType::isTriviallyCopyableType(const ASTContext &Context) const {
24672467
if (hasNonTrivialObjCLifetime())
24682468
return false;
24692469

2470+
PrimitiveCopyKind PCK = isNonTrivialToPrimitiveCopy();
2471+
if (PCK != PCK_Trivial && PCK != PCK_VolatileTrivial)
2472+
return false;
2473+
24702474
// C++11 [basic.types]p9 - See Core 2094
24712475
// Scalar types, trivially copyable class types, arrays of such types, and
24722476
// 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]]* noundef %{{.*}})
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)