[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:
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user