[ARM/AArch64] Enforce alignment for bitfielded structs

When creating a global variable with a type of a struct with bitfields, we must
forcibly set the alignment of the global from the RecordDecl. We must do this so
that the proper bitfield alignment makes its way down to LLVM, since clang will
mangle the bitfields into one large type.

llvm-svn: 235976
This commit is contained in:
Bradley Smith
2015-04-28 11:24:54 +00:00
parent 86e0249235
commit ba945626b0
5 changed files with 49 additions and 0 deletions

View File

@@ -1799,6 +1799,23 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName,
D->getType().isConstant(Context) &&
isExternallyVisible(D->getLinkageAndVisibility().getLinkage()))
GV->setSection(".cp.rodata");
// The ARM/AArch64 ABI expects structs with bitfields to respect the proper
// container alignment, hence we have to enfore this in the IR so as to
// work around clang combining bitfields into one large type.
if (getContext().getTargetInfo().enforceBitfieldContainerAlignment()) {
if (const auto *RT = D->getType()->getAs<RecordType>()) {
const RecordDecl *RD = RT->getDecl();
for (auto I = RD->field_begin(), End = RD->field_end(); I != End; ++I) {
if ((*I)->isBitField()) {
const ASTRecordLayout &Info = getContext().getASTRecordLayout(RD);
GV->setAlignment(Info.getAlignment().getQuantity());
break;
}
}
}
}
}
if (AddrSpace != Ty->getAddressSpace())