]> granicus.if.org Git - clang/commitdiff
Handle reference binding in aggregate initializers. Fixes another 47 tests.
authorAnders Carlsson <andersca@mac.com>
Wed, 3 Feb 2010 19:13:55 +0000 (19:13 +0000)
committerAnders Carlsson <andersca@mac.com>
Wed, 3 Feb 2010 19:13:55 +0000 (19:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95235 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprAgg.cpp
test/CodeGenCXX/references.cpp

index 667fe6714b409f48e33102c1ca4d4689ac96dac6..cb6e1d814030b26ef740d7bbe4a9f7e74d78ef3c 100644 (file)
@@ -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<ImplicitValueInitExpr>(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) {
index 6bec8bd8c3846c1a3d95743b4e645ce8b8fa020c..39b5909fb9a4feb5a3ec5695d8761fc95be88606 100644 (file)
@@ -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() {