diff options
| author | Anders Carlsson <andersca@mac.com> | 2010-04-17 21:04:52 +0000 |
|---|---|---|
| committer | Anders Carlsson <andersca@mac.com> | 2010-04-17 21:04:52 +0000 |
| commit | 2295f13bb0e5d8f8651152adca3a123d6ce5c472 (patch) | |
| tree | f723c2ed509510870e819c3e0e2acbf6da9e4cf0 /clang/lib/CodeGen/CGRecordLayoutBuilder.cpp | |
| parent | 1de2f5710b25b4e3a09f38e6c521b27755bf644e (diff) | |
| download | bcm5719-llvm-2295f13bb0e5d8f8651152adca3a123d6ce5c472.tar.gz bcm5719-llvm-2295f13bb0e5d8f8651152adca3a123d6ce5c472.zip | |
Unnamed bit-fields in a union should be laid out with a type that doesn't affect alignment.
llvm-svn: 101673
Diffstat (limited to 'clang/lib/CodeGen/CGRecordLayoutBuilder.cpp')
| -rw-r--r-- | clang/lib/CodeGen/CGRecordLayoutBuilder.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp index 60ef7fe4093..215b39e7432 100644 --- a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp +++ b/clang/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. |

