forked from OSchip/llvm-project
MS ABI: Just use getTypeInfoInChars to get the field size
This was changed to use manual desugaring and multiplication in r201832 and fixed for multi-dimensional arrays in r201917. However, it breaks down in the presence of typedefs. Rather than attempting to handle all the desugaring, just go back to calling the generic type info code. This was discovered while compiling SIInstrWaits.cpp in the R600 backend. llvm-svn: 202175
This commit is contained in:
parent
00e8a1915a
commit
db673ca26a
|
@ -2261,6 +2261,8 @@ MicrosoftRecordLayoutBuilder::ElementInfo
|
|||
MicrosoftRecordLayoutBuilder::getAdjustedElementInfo(
|
||||
const FieldDecl *FD) {
|
||||
ElementInfo Info;
|
||||
llvm::tie(Info.Size, Info.Alignment) =
|
||||
Context.getTypeInfoInChars(FD->getType());
|
||||
// Respect align attributes.
|
||||
CharUnits FieldRequiredAlignment =
|
||||
Context.toCharUnitsFromBits(FD->getMaxAlignment());
|
||||
|
@ -2269,19 +2271,11 @@ MicrosoftRecordLayoutBuilder::getAdjustedElementInfo(
|
|||
FD->getType()->getBaseElementTypeUnsafe()->getAs<RecordType>()) {
|
||||
const ASTRecordLayout &Layout = Context.getASTRecordLayout(RT->getDecl());
|
||||
// Get the element info for a layout, respecting pack.
|
||||
Info = getAdjustedElementInfo(Layout, false);
|
||||
// If the field is an array type, scale it's size properly.
|
||||
for (const ConstantArrayType *CAT =
|
||||
dyn_cast<ConstantArrayType>(FD->getType()); CAT;
|
||||
CAT = dyn_cast<ConstantArrayType>(CAT->getElementType()))
|
||||
Info.Size = Info.Size * (int64_t)CAT->getSize().getZExtValue();
|
||||
Info.Alignment = getAdjustedElementInfo(Layout, false).Alignment;
|
||||
// Capture required alignment as a side-effect.
|
||||
RequiredAlignment = std::max(RequiredAlignment,
|
||||
Layout.getRequiredAlignment());
|
||||
}
|
||||
else {
|
||||
llvm::tie(Info.Size, Info.Alignment) =
|
||||
Context.getTypeInfoInChars(FD->getType());
|
||||
} else {
|
||||
if (FD->isBitField() && FD->getMaxAlignment() != 0)
|
||||
Info.Alignment = std::max(Info.Alignment, FieldRequiredAlignment);
|
||||
// Respect pragma pack.
|
||||
|
|
|
@ -800,6 +800,22 @@ struct ArrayOfArrayFieldOfRecords {
|
|||
// CHECK-X64-NEXT: | [sizeof=16, align=4
|
||||
// CHECK-X64-NEXT: | nvsize=16, nvalign=4]
|
||||
|
||||
struct RecordArrayTypedef {
|
||||
typedef A4 ArrayTy[2];
|
||||
ArrayTy InlineElts[2];
|
||||
};
|
||||
|
||||
// CHECK: *** Dumping AST Record Layout
|
||||
// CHECK-NEXT: 0 | struct RecordArrayTypedef
|
||||
// CHECK-NEXT: 0 | ArrayTy [2] InlineElts
|
||||
// CHECK-NEXT: | [sizeof=16, align=4
|
||||
// CHECK-NEXT: | nvsize=16, nvalign=4]
|
||||
// CHECK-X64: *** Dumping AST Record Layout
|
||||
// CHECK-X64-NEXT: 0 | struct RecordArrayTypedef
|
||||
// CHECK-X64-NEXT: 0 | ArrayTy [2] InlineElts
|
||||
// CHECK-X64-NEXT: | [sizeof=16, align=4
|
||||
// CHECK-X64-NEXT: | nvsize=16, nvalign=4]
|
||||
|
||||
int a[
|
||||
sizeof(TestF0)+
|
||||
sizeof(TestF1)+
|
||||
|
@ -823,4 +839,5 @@ sizeof(F5)+
|
|||
sizeof(F6)+
|
||||
sizeof(ArrayFieldOfRecords)+
|
||||
sizeof(ArrayOfArrayFieldOfRecords)+
|
||||
sizeof(RecordArrayTypedef)+
|
||||
0];
|
||||
|
|
Loading…
Reference in New Issue