[cfe-commits] r161473 - in /cfe/trunk: lib/CodeGen/CGClass.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CodeGenFunction.h test/CodeGenCXX/anonymous-union-member-initializer.cpp
Eli Friedman
eli.friedman at gmail.com
Tue Aug 7 20:51:38 PDT 2012
Author: efriedma
Date: Tue Aug 7 22:51:37 2012
New Revision: 161473
URL: http://llvm.org/viewvc/llvm-project?rev=161473&view=rev
Log:
Fix an assertion failure with a C++ constructor initializing a
member of reference type in an anonymous struct. PR13154.
Modified:
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/test/CodeGenCXX/anonymous-union-member-initializer.cpp
Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=161473&r1=161472&r2=161473&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Tue Aug 7 22:51:37 2012
@@ -563,16 +563,19 @@
llvm::Value *ThisPtr = CGF.LoadCXXThis();
QualType RecordTy = CGF.getContext().getTypeDeclType(ClassDecl);
- LValue LHS;
+ LValue LHS = CGF.MakeNaturalAlignAddrLValue(ThisPtr, RecordTy);
- // If we are initializing an anonymous union field, drill down to the field.
if (MemberInit->isIndirectMemberInitializer()) {
- LHS = CGF.EmitLValueForAnonRecordField(ThisPtr,
- MemberInit->getIndirectMember(), 0);
+ // If we are initializing an anonymous union field, drill down to
+ // the field.
+ IndirectFieldDecl *IndirectField = MemberInit->getIndirectMember();
+ IndirectFieldDecl::chain_iterator I = IndirectField->chain_begin(),
+ IEnd = IndirectField->chain_end();
+ for ( ; I != IEnd; ++I)
+ LHS = CGF.EmitLValueForFieldInitialization(LHS, cast<FieldDecl>(*I));
FieldType = MemberInit->getIndirectMember()->getAnonField()->getType();
} else {
- LValue ThisLHSLV = CGF.MakeNaturalAlignAddrLValue(ThisPtr, RecordTy);
- LHS = CGF.EmitLValueForFieldInitialization(ThisLHSLV, Field);
+ LHS = CGF.EmitLValueForFieldInitialization(LHS, Field);
}
// Special case: if we are in a copy or move constructor, and we are copying
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=161473&r1=161472&r2=161473&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue Aug 7 22:51:37 2012
@@ -2056,28 +2056,6 @@
llvm_unreachable("Unhandled member declaration!");
}
-/// EmitLValueForAnonRecordField - Given that the field is a member of
-/// an anonymous struct or union buried inside a record, and given
-/// that the base value is a pointer to the enclosing record, derive
-/// an lvalue for the ultimate field.
-LValue CodeGenFunction::EmitLValueForAnonRecordField(llvm::Value *BaseValue,
- const IndirectFieldDecl *Field,
- unsigned CVRQualifiers) {
- IndirectFieldDecl::chain_iterator I = Field->chain_begin(),
- IEnd = Field->chain_end();
- while (true) {
- QualType RecordTy =
- getContext().getTypeDeclType(cast<FieldDecl>(*I)->getParent());
- LValue LV = EmitLValueForField(MakeAddrLValue(BaseValue, RecordTy),
- cast<FieldDecl>(*I));
- if (++I == IEnd) return LV;
-
- assert(LV.isSimple());
- BaseValue = LV.getAddress();
- CVRQualifiers |= LV.getVRQualifiers();
- }
-}
-
LValue CodeGenFunction::EmitLValueForField(LValue base,
const FieldDecl *field) {
if (field->isBitField()) {
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=161473&r1=161472&r2=161473&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Tue Aug 7 22:51:37 2012
@@ -2162,9 +2162,6 @@
llvm::Value *EmitIvarOffset(const ObjCInterfaceDecl *Interface,
const ObjCIvarDecl *Ivar);
- LValue EmitLValueForAnonRecordField(llvm::Value* Base,
- const IndirectFieldDecl* Field,
- unsigned CVRQualifiers);
LValue EmitLValueForField(LValue Base, const FieldDecl* Field);
/// EmitLValueForFieldInitialization - Like EmitLValueForField, except that
Modified: cfe/trunk/test/CodeGenCXX/anonymous-union-member-initializer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/anonymous-union-member-initializer.cpp?rev=161473&r1=161472&r2=161473&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/anonymous-union-member-initializer.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/anonymous-union-member-initializer.cpp Tue Aug 7 22:51:37 2012
@@ -179,3 +179,13 @@
};
QueueEntry QE;
}
+
+namespace PR13154 {
+ struct IndirectReferenceField {
+ struct {
+ float &x;
+ };
+ IndirectReferenceField(float &x);
+ };
+ IndirectReferenceField::IndirectReferenceField(float &xx) : x(xx) {}
+}
More information about the cfe-commits
mailing list