[cfe-commits] r153720 - in /cfe/trunk: lib/CodeGen/CGExprConstant.cpp test/CodeGenCXX/const-init-cxx11.cpp
Eli Friedman
eli.friedman at gmail.com
Thu Mar 29 20:55:32 PDT 2012
Author: efriedma
Date: Thu Mar 29 22:55:31 2012
New Revision: 153720
URL: http://llvm.org/viewvc/llvm-project?rev=153720&view=rev
Log:
ConstStructBuilder: fix offset math for base classes so it works correctly in general. Found by inspection.
Modified:
cfe/trunk/lib/CodeGen/CGExprConstant.cpp
cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp
Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=153720&r1=153719&r2=153720&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Thu Mar 29 22:55:31 2012
@@ -469,21 +469,17 @@
for (unsigned I = 0, N = Bases.size(); I != N; ++I) {
BaseInfo &Base = Bases[I];
- // Build the base class subobject at the appropriately-offset location
- // within this object.
- NextFieldOffsetInChars -= Base.Offset;
bool IsPrimaryBase = Layout.getPrimaryBase() == Base.Decl;
Build(Val.getStructBase(Base.Index), Base.Decl, IsPrimaryBase,
VTable, VTableClass, Offset + Base.Offset);
-
- NextFieldOffsetInChars += Base.Offset;
}
}
unsigned FieldNo = 0;
const FieldDecl *LastFD = 0;
bool IsMsStruct = RD->hasAttr<MsStructAttr>();
+ uint64_t OffsetBits = CGM.getContext().toBits(Offset);
for (RecordDecl::field_iterator Field = RD->field_begin(),
FieldEnd = RD->field_end(); Field != FieldEnd; ++Field, ++FieldNo) {
@@ -516,10 +512,10 @@
if (!Field->isBitField()) {
// Handle non-bitfield members.
- AppendField(*Field, Layout.getFieldOffset(FieldNo), EltInit);
+ AppendField(*Field, Layout.getFieldOffset(FieldNo) + OffsetBits, EltInit);
} else {
// Otherwise we have a bitfield.
- AppendBitField(*Field, Layout.getFieldOffset(FieldNo),
+ AppendBitField(*Field, Layout.getFieldOffset(FieldNo) + OffsetBits,
cast<llvm::ConstantInt>(EltInit));
}
}
Modified: cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp?rev=153720&r1=153719&r2=153720&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp Thu Mar 29 22:55:31 2012
@@ -78,6 +78,11 @@
struct Test2 : X<E,0>, X<E,1>, X<E,2>, X<E,3> {};
// CHECK: @_ZN9BaseClass2t2E = constant {{.*}} undef
extern constexpr Test2 t2 = Test2();
+
+ struct __attribute((packed)) PackedD { double y = 2; };
+ struct Test3 : C, PackedD { constexpr Test3() {} };
+ // CHECK: @_ZN9BaseClass2t3E = constant <{ i8, double }> <{ i8 1, double 2.000000e+00 }>
+ extern constexpr Test3 t3 = Test3();
}
namespace Array {
More information about the cfe-commits
mailing list