diff options
Diffstat (limited to 'lib/CodeGen/CGRecordLayoutBuilder.cpp')
-rw-r--r-- | lib/CodeGen/CGRecordLayoutBuilder.cpp | 54 |
1 files changed, 12 insertions, 42 deletions
diff --git a/lib/CodeGen/CGRecordLayoutBuilder.cpp b/lib/CodeGen/CGRecordLayoutBuilder.cpp index 30ab528..ab92563 100644 --- a/lib/CodeGen/CGRecordLayoutBuilder.cpp +++ b/lib/CodeGen/CGRecordLayoutBuilder.cpp @@ -78,9 +78,6 @@ public: /// Packed - Whether the resulting LLVM struct will be packed or not. bool Packed; - - /// IsMsStruct - Whether ms_struct is in effect or not - bool IsMsStruct; private: CodeGenTypes &Types; @@ -117,7 +114,7 @@ private: RecordDecl::field_iterator &FI, RecordDecl::field_iterator FE); - /// LayoutField - try to layout all fields in the record decl. + /// LayoutFields - try to layout all fields in the record decl. /// Returns false if the operation failed because the struct is not packed. bool LayoutFields(const RecordDecl *D); @@ -195,8 +192,7 @@ public: CGRecordLayoutBuilder(CodeGenTypes &Types) : BaseSubobjectType(0), IsZeroInitializable(true), IsZeroInitializableAsBase(true), - Packed(false), IsMsStruct(false), - Types(Types) { } + Packed(false), Types(Types) { } /// Layout - Will layout a RecordDecl. void Layout(const RecordDecl *D); @@ -205,10 +201,9 @@ public: } void CGRecordLayoutBuilder::Layout(const RecordDecl *D) { - Alignment = Types.getContext().getASTRecordLayout(D).getAlignment(); - Packed = D->hasAttr<PackedAttr>(); - - IsMsStruct = D->isMsStruct(Types.getContext()); + const ASTRecordLayout &Layout = Types.getContext().getASTRecordLayout(D); + Alignment = Layout.getAlignment(); + Packed = D->hasAttr<PackedAttr>() || Layout.getSize() % Alignment != 0; if (D->isUnion()) { LayoutUnion(D); @@ -702,7 +697,7 @@ CGRecordLayoutBuilder::LayoutNonVirtualBases(const CXXRecordDecl *RD, } // Add a vb-table pointer if the layout insists. - if (Layout.getVBPtrOffset() != CharUnits::fromQuantity(-1)) { + if (Layout.hasOwnVBPtr()) { CharUnits VBPtrOffset = Layout.getVBPtrOffset(); llvm::Type *Vbptr = llvm::Type::getInt32PtrTy(Types.getLLVMContext()); AppendPadding(VBPtrOffset, getTypeAlignment(Vbptr)); @@ -764,20 +759,10 @@ bool CGRecordLayoutBuilder::LayoutFields(const RecordDecl *D) { return false; unsigned FieldNo = 0; - const FieldDecl *LastFD = 0; for (RecordDecl::field_iterator FI = D->field_begin(), FE = D->field_end(); FI != FE; ++FI, ++FieldNo) { FieldDecl *FD = *FI; - if (IsMsStruct) { - // Zero-length bitfields following non-bitfield members are - // ignored: - if (Types.getContext().ZeroBitfieldFollowsNonBitfield(FD, LastFD)) { - --FieldNo; - continue; - } - LastFD = FD; - } // If this field is a bitfield, layout all of the consecutive // non-zero-length bitfields and the last zero-length bitfield; these will @@ -992,11 +977,11 @@ CGRecordLayout *CodeGenTypes::ComputeRecordLayout(const RecordDecl *D, // Dump the layout, if requested. if (getContext().getLangOpts().DumpRecordLayouts) { - llvm::errs() << "\n*** Dumping IRgen Record Layout\n"; - llvm::errs() << "Record: "; - D->dump(); - llvm::errs() << "\nLayout: "; - RL->dump(); + llvm::outs() << "\n*** Dumping IRgen Record Layout\n"; + llvm::outs() << "Record: "; + D->dump(llvm::outs()); + llvm::outs() << "\nLayout: "; + RL->print(llvm::outs()); } #ifndef NDEBUG @@ -1028,8 +1013,6 @@ CGRecordLayout *CodeGenTypes::ComputeRecordLayout(const RecordDecl *D, const ASTRecordLayout &AST_RL = getContext().getASTRecordLayout(D); RecordDecl::field_iterator it = D->field_begin(); - const FieldDecl *LastFD = 0; - bool IsMsStruct = D->isMsStruct(getContext()); for (unsigned i = 0, e = AST_RL.getFieldCount(); i != e; ++i, ++it) { const FieldDecl *FD = *it; @@ -1039,25 +1022,12 @@ CGRecordLayout *CodeGenTypes::ComputeRecordLayout(const RecordDecl *D, unsigned FieldNo = RL->getLLVMFieldNo(FD); assert(AST_RL.getFieldOffset(i) == SL->getElementOffsetInBits(FieldNo) && "Invalid field offset!"); - LastFD = FD; continue; } - - if (IsMsStruct) { - // Zero-length bitfields following non-bitfield members are - // ignored: - if (getContext().ZeroBitfieldFollowsNonBitfield(FD, LastFD)) { - --i; - continue; - } - LastFD = FD; - } // Ignore unnamed bit-fields. - if (!FD->getDeclName()) { - LastFD = FD; + if (!FD->getDeclName()) continue; - } // Don't inspect zero-length bitfields. if (FD->getBitWidthValue(getContext()) == 0) |