summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/AST/RecordLayout.h8
-rw-r--r--clang/lib/AST/ASTContext.cpp4
-rw-r--r--clang/lib/AST/RecordLayout.cpp4
-rw-r--r--clang/lib/AST/RecordLayoutBuilder.cpp29
-rw-r--r--clang/lib/CodeGen/CGExprConstant.cpp7
-rw-r--r--clang/lib/CodeGen/CGObjCGNU.cpp5
-rw-r--r--clang/lib/CodeGen/CGObjCMac.cpp5
-rw-r--r--clang/lib/CodeGen/CGRecordLayoutBuilder.cpp15
8 files changed, 45 insertions, 32 deletions
diff --git a/clang/include/clang/AST/RecordLayout.h b/clang/include/clang/AST/RecordLayout.h
index d4423200424..557e790fb70 100644
--- a/clang/include/clang/AST/RecordLayout.h
+++ b/clang/include/clang/AST/RecordLayout.h
@@ -34,7 +34,7 @@ namespace clang {
/// These objects are managed by ASTContext.
class ASTRecordLayout {
/// Size - Size of record in bits.
- uint64_t Size;
+ CharUnits Size;
/// DataSize - Size of record in bits without tail padding.
uint64_t DataSize;
@@ -82,14 +82,14 @@ class ASTRecordLayout {
friend class ASTContext;
- ASTRecordLayout(const ASTContext &Ctx, uint64_t size, unsigned alignment,
+ ASTRecordLayout(const ASTContext &Ctx, CharUnits size, unsigned alignment,
unsigned datasize, const uint64_t *fieldoffsets,
unsigned fieldcount);
// Constructor for C++ records.
typedef CXXRecordLayoutInfo::BaseOffsetsMapTy BaseOffsetsMapTy;
ASTRecordLayout(const ASTContext &Ctx,
- uint64_t size, unsigned alignment, uint64_t datasize,
+ CharUnits size, unsigned alignment, uint64_t datasize,
const uint64_t *fieldoffsets, unsigned fieldcount,
CharUnits nonvirtualsize, CharUnits nonvirtualalign,
CharUnits SizeOfLargestEmptySubobject,
@@ -110,7 +110,7 @@ public:
unsigned getAlignment() const { return Alignment; }
/// getSize - Get the record size in bits.
- uint64_t getSize() const { return Size; }
+ CharUnits getSize() const { return Size; }
/// getFieldCount - Get the number of fields in the layout.
unsigned getFieldCount() const { return FieldCount; }
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 63e84d41313..30fe791e6d3 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -846,7 +846,7 @@ ASTContext::getTypeInfo(const Type *T) const {
case Type::ObjCInterface: {
const ObjCInterfaceType *ObjCI = cast<ObjCInterfaceType>(T);
const ASTRecordLayout &Layout = getASTObjCInterfaceLayout(ObjCI->getDecl());
- Width = Layout.getSize();
+ Width = Layout.getSize().getQuantity() * getCharWidth();
Align = Layout.getAlignment();
break;
}
@@ -865,7 +865,7 @@ ASTContext::getTypeInfo(const Type *T) const {
const RecordType *RT = cast<RecordType>(TT);
const ASTRecordLayout &Layout = getASTRecordLayout(RT->getDecl());
- Width = Layout.getSize();
+ Width = Layout.getSize().getQuantity() * getCharWidth();
Align = Layout.getAlignment();
break;
}
diff --git a/clang/lib/AST/RecordLayout.cpp b/clang/lib/AST/RecordLayout.cpp
index 32e3821ca24..2acf97523c1 100644
--- a/clang/lib/AST/RecordLayout.cpp
+++ b/clang/lib/AST/RecordLayout.cpp
@@ -27,7 +27,7 @@ void ASTRecordLayout::Destroy(ASTContext &Ctx) {
Ctx.Deallocate(this);
}
-ASTRecordLayout::ASTRecordLayout(const ASTContext &Ctx, uint64_t size,
+ASTRecordLayout::ASTRecordLayout(const ASTContext &Ctx, CharUnits size,
unsigned alignment, unsigned datasize,
const uint64_t *fieldoffsets,
unsigned fieldcount)
@@ -41,7 +41,7 @@ ASTRecordLayout::ASTRecordLayout(const ASTContext &Ctx, uint64_t size,
// Constructor for C++ records.
ASTRecordLayout::ASTRecordLayout(const ASTContext &Ctx,
- uint64_t size, unsigned alignment,
+ CharUnits size, unsigned alignment,
uint64_t datasize,
const uint64_t *fieldoffsets,
unsigned fieldcount,
diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp b/clang/lib/AST/RecordLayoutBuilder.cpp
index 6b98ecd87da..62306894ab6 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -148,7 +148,7 @@ void EmptySubobjectMap::ComputeEmptySubobjectSizes() {
const ASTRecordLayout &Layout = Context.getASTRecordLayout(BaseDecl);
if (BaseDecl->isEmpty()) {
// If the class decl is empty, get its size.
- EmptySize = Context.toCharUnitsFromBits(Layout.getSize());
+ EmptySize = Layout.getSize();
} else {
// Otherwise, we get the largest empty subobject for the decl.
EmptySize = Layout.getSizeOfLargestEmptySubobject();
@@ -175,7 +175,7 @@ void EmptySubobjectMap::ComputeEmptySubobjectSizes() {
const ASTRecordLayout &Layout = Context.getASTRecordLayout(MemberDecl);
if (MemberDecl->isEmpty()) {
// If the class decl is empty, get its size.
- EmptySize = Context.toCharUnitsFromBits(Layout.getSize());
+ EmptySize = Layout.getSize();
} else {
// Otherwise, we get the largest empty subobject for the decl.
EmptySize = Layout.getSizeOfLargestEmptySubobject();
@@ -428,7 +428,7 @@ EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const FieldDecl *FD,
if (!CanPlaceFieldSubobjectAtOffset(RD, RD, ElementOffset))
return false;
- ElementOffset += Context.toCharUnitsFromBits(Layout.getSize());
+ ElementOffset += Layout.getSize();
}
}
@@ -533,7 +533,7 @@ void EmptySubobjectMap::UpdateEmptyFieldSubobjects(const FieldDecl *FD,
return;
UpdateEmptyFieldSubobjects(RD, RD, ElementOffset);
- ElementOffset += Context.toCharUnitsFromBits(Layout.getSize());
+ ElementOffset += Layout.getSize();
}
}
}
@@ -1091,7 +1091,8 @@ CharUnits RecordLayoutBuilder::LayoutBase(const BaseSubobjectInfo *Base) {
// If we have an empty base class, try to place it at offset 0.
if (Base->Class->isEmpty() &&
EmptySubobjects->CanPlaceBaseAtOffset(Base, CharUnits::Zero())) {
- Size = std::max(Size, Layout.getSize());
+ Size = std::max(Size,
+ Layout.getSize().getQuantity() * Context.getCharWidth());
return CharUnits::Zero();
}
@@ -1121,7 +1122,8 @@ CharUnits RecordLayoutBuilder::LayoutBase(const BaseSubobjectInfo *Base) {
Size = std::max(Size, DataSize);
} else
- Size = std::max(Size, Offset + Layout.getSize());
+ Size = std::max(Size,
+ Offset + (Layout.getSize().getQuantity() * Context.getCharWidth()));
// Remember max struct/class alignment.
UpdateAlignment(BaseAlign, UnpackedBaseAlign);
@@ -1687,8 +1689,9 @@ ASTContext::getASTRecordLayout(const RecordDecl *D) const {
IsPODForThePurposeOfLayout ? DataSize : Builder->NonVirtualSize;
uint64_t NonVirtualAlign = Builder->NonVirtualAlignment;
+ CharUnits RecordSize = toCharUnitsFromBits(Builder->Size);
NewEntry =
- new (*this) ASTRecordLayout(*this, Builder->Size, Builder->Alignment,
+ new (*this) ASTRecordLayout(*this, RecordSize, Builder->Alignment,
DataSize, Builder->FieldOffsets.data(),
Builder->FieldOffsets.size(),
toCharUnitsFromBits(NonVirtualSize),
@@ -1701,8 +1704,10 @@ ASTContext::getASTRecordLayout(const RecordDecl *D) const {
RecordLayoutBuilder Builder(*this, /*EmptySubobjects=*/0);
Builder.Layout(D);
+ CharUnits RecordSize = toCharUnitsFromBits(Builder.Size);
+
NewEntry =
- new (*this) ASTRecordLayout(*this, Builder.Size, Builder.Alignment,
+ new (*this) ASTRecordLayout(*this, RecordSize, Builder.Alignment,
Builder.Size,
Builder.FieldOffsets.data(),
Builder.FieldOffsets.size());
@@ -1759,8 +1764,10 @@ ASTContext::getObjCLayout(const ObjCInterfaceDecl *D,
RecordLayoutBuilder Builder(*this, /*EmptySubobjects=*/0);
Builder.Layout(D);
+ CharUnits RecordSize = toCharUnitsFromBits(Builder.Size);
+
const ASTRecordLayout *NewEntry =
- new (*this) ASTRecordLayout(*this, Builder.Size, Builder.Alignment,
+ new (*this) ASTRecordLayout(*this, RecordSize, Builder.Alignment,
Builder.DataSize,
Builder.FieldOffsets.data(),
Builder.FieldOffsets.size());
@@ -1857,7 +1864,7 @@ static void DumpCXXRecordLayout(llvm::raw_ostream &OS,
/*IncludeVirtualBases=*/false);
}
- OS << " sizeof=" << Layout.getSize() / 8;
+ OS << " sizeof=" << Layout.getSize().getQuantity();
OS << ", dsize=" << Layout.getDataSize() / 8;
OS << ", align=" << Layout.getAlignment() / 8 << '\n';
OS << " nvsize=" << Layout.getNonVirtualSize().getQuantity();
@@ -1878,7 +1885,7 @@ void ASTContext::DumpRecordLayout(const RecordDecl *RD,
RD->dump();
OS << "\nLayout: ";
OS << "<ASTRecordLayout\n";
- OS << " Size:" << Info.getSize() << "\n";
+ OS << " Size:" << Info.getSize().getQuantity() * getCharWidth() << "\n";
OS << " DataSize:" << Info.getDataSize() << "\n";
OS << " Alignment:" << Info.getAlignment() << "\n";
OS << " FieldOffsets: [";
diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp
index 4d8a60e1e8f..dc84b367cf0 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -368,7 +368,7 @@ bool ConstStructBuilder::Build(InitListExpr *ILE) {
}
}
- uint64_t LayoutSizeInBytes = Layout.getSize() / 8;
+ uint64_t LayoutSizeInBytes = Layout.getSize().getQuantity();
if (NextFieldOffsetInBytes > LayoutSizeInBytes) {
// If the struct is bigger than the size of the record type,
@@ -394,9 +394,10 @@ bool ConstStructBuilder::Build(InitListExpr *ILE) {
}
// Append tail padding if necessary.
- AppendTailPadding(Layout.getSize());
+ AppendTailPadding(
+ Layout.getSize().getQuantity() * CGM.getContext().getCharWidth());
- assert(Layout.getSize() / 8 == NextFieldOffsetInBytes &&
+ assert(Layout.getSize().getQuantity() == NextFieldOffsetInBytes &&
"Tail padding mismatch!");
return true;
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4f65dddfdd9..d481e779267 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -1437,7 +1437,8 @@ void CGObjCGNU::GenerateClass(const ObjCImplementationDecl *OID) {
}
// Get the size of instances.
- int instanceSize = Context.getASTObjCImplementationLayout(OID).getSize() / 8;
+ int instanceSize =
+ Context.getASTObjCImplementationLayout(OID).getSize().getQuantity();
// Collect information about instance variables.
llvm::SmallVector<llvm::Constant*, 16> IvarNames;
@@ -1447,7 +1448,7 @@ void CGObjCGNU::GenerateClass(const ObjCImplementationDecl *OID) {
std::vector<llvm::Constant*> IvarOffsetValues;
int superInstanceSize = !SuperClassDecl ? 0 :
- Context.getASTObjCInterfaceLayout(SuperClassDecl).getSize() / 8;
+ Context.getASTObjCInterfaceLayout(SuperClassDecl).getSize().getQuantity();
// For non-fragile ivars, set the instance size to 0 - {the size of just this
// class}. The runtime will then set this to the correct value on load.
if (CGM.getContext().getLangOptions().ObjCNonFragileABI) {
diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index be7c79cbb56..3cbb296b0b2 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -131,7 +131,8 @@ LValue CGObjCRuntime::EmitValueForIvarAtOffset(CodeGen::CodeGenFunction &CGF,
// a synthesized ivar can never be a bit-field, so this is safe.
const ASTRecordLayout &RL =
CGF.CGM.getContext().getASTObjCInterfaceLayout(OID);
- uint64_t TypeSizeInBits = RL.getSize();
+ uint64_t TypeSizeInBits =
+ RL.getSize().getQuantity() * CGF.CGM.getContext().getCharWidth();
uint64_t FieldBitOffset = LookupFieldBitOffset(CGF.CGM, OID, 0, Ivar);
uint64_t BitOffset = FieldBitOffset % 8;
uint64_t ContainingTypeAlign = 8;
@@ -2214,7 +2215,7 @@ void CGObjCMac::GenerateClass(const ObjCImplementationDecl *ID) {
if (ID->getNumIvarInitializers())
Flags |= eClassFlags_HasCXXStructors;
unsigned Size =
- CGM.getContext().getASTObjCImplementationLayout(ID).getSize() / 8;
+ CGM.getContext().getASTObjCImplementationLayout(ID).getSize().getQuantity();
// FIXME: Set CXX-structors flag.
if (ID->getClassInterface()->getVisibility() == HiddenVisibility)
diff --git a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
index e158eed9878..e16173b6dca 100644
--- a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
+++ b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
@@ -300,7 +300,8 @@ CGBitFieldInfo CGBitFieldInfo::MakeInfo(CodeGenTypes &Types,
uint64_t FieldSize) {
const RecordDecl *RD = FD->getParent();
const ASTRecordLayout &RL = Types.getContext().getASTRecordLayout(RD);
- uint64_t ContainingTypeSizeInBits = RL.getSize();
+ uint64_t ContainingTypeSizeInBits =
+ RL.getSize().getQuantity() * Types.getContext().getCharWidth();
unsigned ContainingTypeAlign = RL.getAlignment();
return MakeInfo(Types, FD, FieldOffset, FieldSize, ContainingTypeSizeInBits,
@@ -489,8 +490,8 @@ void CGRecordLayoutBuilder::LayoutUnion(const RecordDecl *D) {
}
// Append tail padding.
- if (Layout.getSize() / 8 > Size)
- AppendPadding(Layout.getSize() / 8, Align);
+ if (Layout.getSize().getQuantity() > Size)
+ AppendPadding(Layout.getSize().getQuantity(), Align);
}
void CGRecordLayoutBuilder::LayoutBase(const CXXRecordDecl *BaseDecl,
@@ -624,7 +625,7 @@ CGRecordLayoutBuilder::ComputeNonVirtualBaseType(const CXXRecordDecl *RD) {
// First check if we can use the same fields as for the complete class.
- if (AlignedNonVirtualTypeSize == Layout.getSize() / 8) {
+ if (AlignedNonVirtualTypeSize == Layout.getSize().getQuantity()) {
NonVirtualBaseTypeIsSameAsCompleteType = true;
return true;
}
@@ -686,7 +687,8 @@ bool CGRecordLayoutBuilder::LayoutFields(const RecordDecl *D) {
}
// Append tail padding if necessary.
- AppendTailPadding(Layout.getSize());
+ AppendTailPadding(
+ Layout.getSize().getQuantity() * Types.getContext().getCharWidth());
return true;
}
@@ -851,7 +853,8 @@ CGRecordLayout *CodeGenTypes::ComputeRecordLayout(const RecordDecl *D) {
// Verify that the computed LLVM struct size matches the AST layout size.
const ASTRecordLayout &Layout = getContext().getASTRecordLayout(D);
- uint64_t TypeSizeInBits = Layout.getSize();
+ uint64_t TypeSizeInBits =
+ Layout.getSize().getQuantity() * getContext().getCharWidth();
assert(TypeSizeInBits == getTargetData().getTypeAllocSizeInBits(Ty) &&
"Type size mismatch!");
OpenPOWER on IntegriCloud