From ec4408ad692b20a01cca8b5d86f359f6f16bae87 Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Thu, 25 Feb 2021 12:11:18 -0800 Subject: [PATCH] [CodeGen] Call ConvertTypeForMem instead of ConvertType This fixes a crash that occurs when the type passed to the method is `_Bool`. rdar://74493389 --- clang/lib/CodeGen/CGNonTrivialStruct.cpp | 2 +- clang/test/CodeGenObjC/strong-in-c-struct.m | 23 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CGNonTrivialStruct.cpp b/clang/lib/CodeGen/CGNonTrivialStruct.cpp index d134be83a9dc..bf164d242c7d 100644 --- a/clang/lib/CodeGen/CGNonTrivialStruct.cpp +++ b/clang/lib/CodeGen/CGNonTrivialStruct.cpp @@ -568,7 +568,7 @@ struct GenBinaryFunc : CopyStructVisitor, this->CGF->Builder.CreateBitCast(SrcAddr, PtrTy), FT); SrcLV = this->CGF->EmitLValueForField(SrcBase, FD); } else { - llvm::PointerType *Ty = this->CGF->ConvertType(FT)->getPointerTo(); + llvm::PointerType *Ty = this->CGF->ConvertTypeForMem(FT)->getPointerTo(); Address DstAddr = this->CGF->Builder.CreateBitCast(Addrs[DstIdx], Ty); Address SrcAddr = this->CGF->Builder.CreateBitCast(Addrs[SrcIdx], Ty); DstLV = this->CGF->MakeAddrLValue(DstAddr, FT); diff --git a/clang/test/CodeGenObjC/strong-in-c-struct.m b/clang/test/CodeGenObjC/strong-in-c-struct.m index 6033385e30cb..3d7ce0886150 100644 --- a/clang/test/CodeGenObjC/strong-in-c-struct.m +++ b/clang/test/CodeGenObjC/strong-in-c-struct.m @@ -79,6 +79,11 @@ typedef struct { volatile int a[16]; } VolatileArray ; +typedef struct { + _Bool f0[2]; + VolatileArray f1; +} StructWithBool; + #endif #ifdef USESTRUCT @@ -539,6 +544,24 @@ void test_copy_assignment_StrongBlock(StrongBlock *d, StrongBlock *s) { *d = *s; } +// CHECK-LABEL: define{{.*}} void @test_copy_assignment_StructWithBool( +// CHECK: call void @__copy_assignment_8_8_AB0s1n2_tv0w8_AE_S_sv8_AB16s4n16_tv128w32_AE( + +// CHECK-LABEL: define linkonce_odr hidden void @__copy_assignment_8_8_AB0s1n2_tv0w8_AE_S_sv8_AB16s4n16_tv128w32_AE( +// CHECK: %[[ADDR_CUR:.*]] = phi i8** +// CHECK: %[[ADDR_CUR1:.*]] = phi i8** + +// CHECK: %[[V4:.*]] = bitcast i8** %[[ADDR_CUR]] to i8* +// CHECK: %[[V5:.*]] = bitcast i8** %[[ADDR_CUR1]] to i8* +// CHECK: %[[V6:.*]] = load volatile i8, i8* %[[V5]], align 1 +// CHECK: %[[TOBOOL:.*]] = trunc i8 %[[V6]] to i1 +// CHECK: %[[FROMBOOL:.*]] = zext i1 %[[TOBOOL]] to i8 +// CHECK: store volatile i8 %[[FROMBOOL]], i8* %[[V4]], align 1 + +void test_copy_assignment_StructWithBool(StructWithBool *d, StructWithBool *s) { + *d = *s; +} + // CHECK: define{{.*}} void @test_copy_constructor_StrongVolatile0( // CHECK: call void @__copy_constructor_8_8_t0w4_sv8( // CHECK-NOT: call