diff options
author | Akira Hatanaka <ahatanaka@apple.com> | 2018-04-16 19:53:59 +0000 |
---|---|---|
committer | Akira Hatanaka <ahatanaka@apple.com> | 2018-04-16 19:53:59 +0000 |
commit | d55675d068cf7e665a0b70207c1a5d4f62b6bfdf (patch) | |
tree | ed0bde051b2c4993233509f80f0b4c04c82ce571 | |
parent | a3b5f71eaa924f71321fb989d727a3a6365ba557 (diff) | |
download | bcm5719-llvm-d55675d068cf7e665a0b70207c1a5d4f62b6bfdf.tar.gz bcm5719-llvm-d55675d068cf7e665a0b70207c1a5d4f62b6bfdf.zip |
Revert "[CodeGen] Fix a crash that occurs when a non-trivial C struct with a"
This reverts commit r330151, which caused bots to fail.
llvm-svn: 330153
-rw-r--r-- | clang/lib/CodeGen/CGNonTrivialStruct.cpp | 40 | ||||
-rw-r--r-- | clang/test/CodeGenObjC/strong-in-c-struct.m | 18 |
2 files changed, 15 insertions, 43 deletions
diff --git a/clang/lib/CodeGen/CGNonTrivialStruct.cpp b/clang/lib/CodeGen/CGNonTrivialStruct.cpp index 4f1708497b6..731938af867 100644 --- a/clang/lib/CodeGen/CGNonTrivialStruct.cpp +++ b/clang/lib/CodeGen/CGNonTrivialStruct.cpp @@ -21,11 +21,10 @@ using namespace clang; using namespace CodeGen; // Return the size of a field in number of bits. -static uint64_t getFieldSize(const FieldDecl *FD, QualType FT, - ASTContext &Ctx) { - if (FD && FD->isBitField()) +static uint64_t getFieldSize(const FieldDecl *FD, ASTContext &Ctx) { + if (FD->isBitField()) return FD->getBitWidthValue(Ctx); - return Ctx.getTypeSize(FT); + return Ctx.getTypeSize(FD->getType()); } namespace { @@ -188,7 +187,7 @@ struct CopyStructVisitor : StructVisitor<Derived>, Ts... Args) { assert(!FT.isVolatileQualified() && "volatile field not expected"); ASTContext &Ctx = asDerived().getContext(); - uint64_t FieldSize = getFieldSize(FD, FT, Ctx); + uint64_t FieldSize = getFieldSize(FD, Ctx); // Ignore zero-sized fields. if (FieldSize == 0) @@ -337,7 +336,7 @@ struct GenBinaryFuncName : CopyStructVisitor<GenBinaryFuncName<IsMove>, IsMove>, uint64_t OffsetInBits = this->Ctx.toBits(CurStackOffset) + this->getFieldOffsetInBits(FD); this->appendStr("_tv" + llvm::to_string(OffsetInBits) + "w" + - llvm::to_string(getFieldSize(FD, FT, this->Ctx))); + llvm::to_string(getFieldSize(FD, this->Ctx))); } }; @@ -596,25 +595,16 @@ struct GenBinaryFunc : CopyStructVisitor<Derived, IsMove>, template <class... Ts> void visitVolatileTrivial(QualType FT, const FieldDecl *FD, CharUnits Offset, std::array<Address, 2> Addrs) { - LValue DstLV, SrcLV; - if (FD) { - QualType RT = QualType(FD->getParent()->getTypeForDecl(), 0); - llvm::PointerType *PtrTy = this->CGF->ConvertType(RT)->getPointerTo(); - Address DstAddr = this->getAddrWithOffset(Addrs[DstIdx], Offset); - LValue DstBase = this->CGF->MakeAddrLValue( - this->CGF->Builder.CreateBitCast(DstAddr, PtrTy), FT); - DstLV = this->CGF->EmitLValueForField(DstBase, FD); - Address SrcAddr = this->getAddrWithOffset(Addrs[SrcIdx], Offset); - LValue SrcBase = this->CGF->MakeAddrLValue( - this->CGF->Builder.CreateBitCast(SrcAddr, PtrTy), FT); - SrcLV = this->CGF->EmitLValueForField(SrcBase, FD); - } else { - llvm::PointerType *Ty = this->CGF->ConvertType(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); - SrcLV = this->CGF->MakeAddrLValue(SrcAddr, FT); - } + QualType RT = QualType(FD->getParent()->getTypeForDecl(), 0); + llvm::PointerType *PtrTy = this->CGF->ConvertType(RT)->getPointerTo(); + Address DstAddr = this->getAddrWithOffset(Addrs[DstIdx], Offset); + LValue DstBase = this->CGF->MakeAddrLValue( + this->CGF->Builder.CreateBitCast(DstAddr, PtrTy), FT); + LValue DstLV = this->CGF->EmitLValueForField(DstBase, FD); + Address SrcAddr = this->getAddrWithOffset(Addrs[SrcIdx], Offset); + LValue SrcBase = this->CGF->MakeAddrLValue( + this->CGF->Builder.CreateBitCast(SrcAddr, PtrTy), FT); + LValue SrcLV = this->CGF->EmitLValueForField(SrcBase, FD); RValue SrcVal = this->CGF->EmitLoadOfLValue(SrcLV, SourceLocation()); this->CGF->EmitStoreThroughLValue(SrcVal, DstLV); } diff --git a/clang/test/CodeGenObjC/strong-in-c-struct.m b/clang/test/CodeGenObjC/strong-in-c-struct.m index 393a328ca8d..6310943d2ef 100644 --- a/clang/test/CodeGenObjC/strong-in-c-struct.m +++ b/clang/test/CodeGenObjC/strong-in-c-struct.m @@ -70,11 +70,6 @@ typedef struct { volatile char i6; } Bitfield1; -typedef struct { - id x; - volatile int a[16]; -} VolatileArray ; - #endif #ifdef USESTRUCT @@ -545,17 +540,4 @@ void test_strong_in_union() { U t; } -// CHECK: define void @test_copy_constructor_VolatileArray( -// CHECK: call void @__copy_constructor_8_8_s0_AB8s4n16_tv64w32_AE( - -// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_s0_AB8s4n16_tv64w32_AE( -// CHECK: %[[V12:.*]] = bitcast i8** %{{.*}} to i32* -// CHECK: %[[V13:.*]] = bitcast i8** %{{.*}} to i32* -// CHECK: %[[V14:.*]] = load volatile i32, i32* %[[V13]], align 4 -// CHECK: store volatile i32 %[[V14]], i32* %[[V12]], align 4 - -void test_copy_constructor_VolatileArray(VolatileArray *a) { - VolatileArray t = *a; -} - #endif /* USESTRUCT */ |