From: Anders Carlsson Date: Wed, 3 Feb 2010 19:13:55 +0000 (+0000) Subject: Handle reference binding in aggregate initializers. Fixes another 47 tests. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e78ccb4d609a113c3e06a9c4583e845e90b1a037;p=clang Handle reference binding in aggregate initializers. Fixes another 47 tests. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95235 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp index 667fe6714b..cb6e1d8140 100644 --- a/lib/CodeGen/CGExprAgg.cpp +++ b/lib/CodeGen/CGExprAgg.cpp @@ -514,13 +514,13 @@ void AggExprEmitter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { void AggExprEmitter::EmitInitializationToLValue(Expr* E, LValue LV, QualType T) { - // FIXME: Remove this. - T = E->getType(); - // FIXME: Ignore result? // FIXME: Are initializers affected by volatile? if (isa(E)) { EmitNullInitializationToLValue(LV, T); + } else if (T->isReferenceType()) { + RValue RV = CGF.EmitReferenceBindingToExpr(E, /*IsInitializer=*/false); + CGF.EmitStoreThroughLValue(RV, LV, T); } else if (T->isAnyComplexType()) { CGF.EmitComplexExprIntoAddr(E, LV.getAddress(), false); } else if (CGF.hasAggregateLLVMType(T)) { @@ -633,7 +633,7 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) { // FIXME: volatility FieldDecl *Field = E->getInitializedFieldInUnion(); - LValue FieldLoc = CGF.EmitLValueForField(DestPtr, Field, 0); + LValue FieldLoc = CGF.EmitLValueForFieldInitialization(DestPtr, Field, 0); if (NumInitElements) { // Store the initializer into the field @@ -659,7 +659,7 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) { continue; // FIXME: volatility - LValue FieldLoc = CGF.EmitLValueForField(DestPtr, *Field, 0); + LValue FieldLoc = CGF.EmitLValueForFieldInitialization(DestPtr, *Field, 0); // We never generate write-barries for initialized fields. LValue::SetObjCNonGC(FieldLoc, true); if (CurInitVal < NumInitElements) { diff --git a/test/CodeGenCXX/references.cpp b/test/CodeGenCXX/references.cpp index 6bec8bd8c3..39b5909fb9 100644 --- a/test/CodeGenCXX/references.cpp +++ b/test/CodeGenCXX/references.cpp @@ -38,6 +38,8 @@ void test_bool() { bool_reference_return() = true; a = bool_reference_return(); + + struct { const bool& b; } b = { true }; } void test_scalar() { @@ -54,6 +56,8 @@ void test_scalar() { int_reference_return() = 10; a = int_reference_return(); + + struct { const int& a; } agg = { 10 }; } void test_complex() { @@ -64,6 +68,8 @@ void test_complex() { complex_int_reference_return() = 10i; a = complex_int_reference_return(); + + struct { const _Complex int &a; } agg = { 10i }; } void test_aggregate() { @@ -74,6 +80,8 @@ void test_aggregate() { aggregate_reference_return().a = 10; c = aggregate_reference_return(); + + struct { const C& a; } agg = { C() }; } int& reference_return() {