r220031 - D5775: Fix of assertion failure in case of non-POD unions with bitfields. Patch by Evgeny Astigeevich!
Artyom Skrobov
Artyom.Skrobov at arm.com
Fri Oct 17 03:22:03 PDT 2014
Author: askrobov
Date: Fri Oct 17 05:22:03 2014
New Revision: 220031
URL: http://llvm.org/viewvc/llvm-project?rev=220031&view=rev
Log:
D5775: Fix of assertion failure in case of non-POD unions with bitfields. Patch by Evgeny Astigeevich!
Modified:
cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=220031&r1=220030&r2=220031&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Fri Oct 17 05:22:03 2014
@@ -1335,6 +1335,14 @@ void RecordLayoutBuilder::LayoutFields(c
LayoutField(Field, InsertExtraPadding);
}
+// Rounds the specified size to have it a multiple of the char size.
+static uint64_t
+roundUpSizeToCharAlignment(uint64_t Size,
+ const ASTContext &Context) {
+ uint64_t CharAlignment = Context.getTargetInfo().getCharAlign();
+ return llvm::RoundUpToAlignment(Size, CharAlignment);
+}
+
void RecordLayoutBuilder::LayoutWideBitField(uint64_t FieldSize,
uint64_t TypeSize,
bool FieldPacked,
@@ -1372,7 +1380,9 @@ void RecordLayoutBuilder::LayoutWideBitF
uint64_t UnpaddedFieldOffset = getDataSizeInBits() - UnfilledBitsInLastUnit;
if (IsUnion) {
- setDataSize(std::max(getDataSizeInBits(), FieldSize));
+ uint64_t RoundedFieldSize = roundUpSizeToCharAlignment(FieldSize,
+ Context);
+ setDataSize(std::max(getDataSizeInBits(), RoundedFieldSize));
FieldOffset = 0;
} else {
// The bitfield is allocated starting at the next offset aligned
@@ -1597,9 +1607,9 @@ void RecordLayoutBuilder::LayoutBitField
// For unions, this is just a max operation, as usual.
if (IsUnion) {
- // FIXME: I think FieldSize should be TypeSize here.
- setDataSize(std::max(getDataSizeInBits(), FieldSize));
-
+ uint64_t RoundedFieldSize = roundUpSizeToCharAlignment(FieldSize,
+ Context);
+ setDataSize(std::max(getDataSizeInBits(), RoundedFieldSize));
// For non-zero-width bitfields in ms_struct structs, allocate a new
// storage unit if necessary.
} else if (IsMsStruct && FieldSize) {
More information about the cfe-commits
mailing list