aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGRecordLayoutBuilder.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2010-04-17 21:04:52 +0000
committerAnders Carlsson <andersca@mac.com>2010-04-17 21:04:52 +0000
commitd62328e6a0fa933e3a5daaf68e4964031e6c5c5e (patch)
treed410d84f978d31b2a8b414fb83162eb12bfe91dc /lib/CodeGen/CGRecordLayoutBuilder.cpp
parent86664465bac330871d4a476f68a1d6f7f6f102af (diff)
Unnamed bit-fields in a union should be laid out with a type that doesn't affect alignment.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101673 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGRecordLayoutBuilder.cpp')
-rw-r--r--lib/CodeGen/CGRecordLayoutBuilder.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/CodeGen/CGRecordLayoutBuilder.cpp b/lib/CodeGen/CGRecordLayoutBuilder.cpp
index 60ef7fe409..215b39e743 100644
--- a/lib/CodeGen/CGRecordLayoutBuilder.cpp
+++ b/lib/CodeGen/CGRecordLayoutBuilder.cpp
@@ -332,10 +332,26 @@ CGRecordLayoutBuilder::LayoutUnionField(const FieldDecl *Field,
if (FieldSize == 0)
return 0;
+ const llvm::Type *FieldTy;
+
+ if (!Field->getDeclName()) {
+ // This is an unnamed bit-field, which shouldn't affect alignment on the
+ // struct so we use an array of bytes for it.
+
+ FieldTy = llvm::Type::getInt8Ty(Types.getLLVMContext());
+
+ unsigned NumBytesToAppend =
+ llvm::RoundUpToAlignment(FieldSize, 8) / 8;
+
+ if (NumBytesToAppend > 1)
+ FieldTy = llvm::ArrayType::get(FieldTy, NumBytesToAppend);
+ } else
+ FieldTy = Types.ConvertTypeForMemRecursive(Field->getType());
+
// Add the bit field info.
LLVMBitFields.push_back(
LLVMBitFieldInfo(Field, ComputeBitFieldInfo(Types, Field, 0, FieldSize)));
- return Types.ConvertTypeForMemRecursive(Field->getType());
+ return FieldTy;
}
// This is a regular union field.