[cfe-commits] r94327 - in /cfe/trunk: lib/Sema/SemaInit.cpp test/SemaCXX/aggregate-initialization.cpp

Anders Carlsson andersca at mac.com
Sat Jan 23 12:13:41 PST 2010


Author: andersca
Date: Sat Jan 23 14:13:41 2010
New Revision: 94327

URL: http://llvm.org/viewvc/llvm-project?rev=94327&view=rev
Log:
Switch some array initialization over to the new init code.

Modified:
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/test/SemaCXX/aggregate-initialization.cpp

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=94327&r1=94326&r2=94327&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Sat Jan 23 14:13:41 2010
@@ -242,7 +242,8 @@
                              InitListExpr *StructuredList,
                              unsigned &StructuredIndex,
                              bool TopLevelObject = false);
-  void CheckArrayType(InitListExpr *IList, QualType &DeclType,
+  void CheckArrayType(const InitializedEntity *Entity,
+                      InitListExpr *IList, QualType &DeclType,
                       llvm::APSInt elementIndex,
                       bool SubobjectIsDesignatorContext, unsigned &Index,
                       InitListExpr *StructuredList,
@@ -640,7 +641,8 @@
       llvm::APSInt Zero(
                       SemaRef.Context.getTypeSize(SemaRef.Context.getSizeType()),
                       false);
-      CheckArrayType(IList, DeclType, Zero, SubobjectIsDesignatorContext, Index,
+      CheckArrayType(Entity, IList, DeclType, Zero, 
+                     SubobjectIsDesignatorContext, Index,
                      StructuredList, StructuredIndex);
     } else
       assert(0 && "Aggregate that isn't a structure or array?!");
@@ -932,7 +934,8 @@
   }
 }
 
-void InitListChecker::CheckArrayType(InitListExpr *IList, QualType &DeclType,
+void InitListChecker::CheckArrayType(const InitializedEntity *Entity,
+                                     InitListExpr *IList, QualType &DeclType,
                                      llvm::APSInt elementIndex,
                                      bool SubobjectIsDesignatorContext,
                                      unsigned &Index,
@@ -1020,9 +1023,20 @@
     if (maxElementsKnown && elementIndex == maxElements)
       break;
 
-    // Check this element.
-    CheckSubElementType(0, IList, elementType, Index,
-                        StructuredList, StructuredIndex);
+    // FIXME: Once we know that Entity is not null, we can remove this check,
+    // and the else block.
+    if (Entity) {
+      InitializedEntity ElementEntity =
+      InitializedEntity::InitializeElement(SemaRef.Context, StructuredIndex, 
+                                           *Entity);
+      // Check this element.
+      CheckSubElementType(&ElementEntity, IList, elementType, Index,
+                          StructuredList, StructuredIndex);
+    } else {
+      // Check this element.
+      CheckSubElementType(0, IList, elementType, Index,
+                          StructuredList, StructuredIndex);
+    }      
     ++elementIndex;
 
     // If the array is of incomplete type, keep track of the number of
@@ -1649,7 +1663,8 @@
 
   // Check the remaining elements within this array subobject.
   bool prevHadError = hadError;
-  CheckArrayType(IList, CurrentObjectType, DesignatedStartIndex, false, Index,
+  CheckArrayType(0, IList, CurrentObjectType, DesignatedStartIndex, 
+                 /*SubobjectIsDesignatorContext=*/false, Index,
                  StructuredList, ElementIndex);
   return hadError && !prevHadError;
 }

Modified: cfe/trunk/test/SemaCXX/aggregate-initialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/aggregate-initialization.cpp?rev=94327&r1=94326&r2=94327&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/aggregate-initialization.cpp (original)
+++ cfe/trunk/test/SemaCXX/aggregate-initialization.cpp Sat Jan 23 14:13:41 2010
@@ -34,3 +34,6 @@
 // Vector initialization.
 typedef short __v4hi __attribute__ ((__vector_size__ (8)));
 __v4hi v1 = { (void *)1, 2, 3 }; // expected-error {{cannot initialize a vector element of type 'short' with an rvalue of type 'void *'}}
+
+// Array initialization.
+int a[] = { (void *)1 }; // expected-error {{cannot initialize an array element of type 'int' with an rvalue of type 'void *'}}





More information about the cfe-commits mailing list