Finally fix PR2189.  This makes a fairly invasive but important change to
move getAsArrayType into ASTContext instead of being a method on type.
This is required because getAsArrayType(const AT), where AT is a typedef
for "int[10]" needs to return ArrayType(const int, 10).

Fixing this greatly simplifies getArrayDecayedType, which is a good sign.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54317 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp
index 0078cc1..1889baf 100644
--- a/lib/Sema/SemaInit.cpp
+++ b/lib/Sema/SemaInit.cpp
@@ -30,7 +30,8 @@
 int InitListChecker::numArrayElements(QualType DeclType) {
   // FIXME: use a proper constant
   int maxElements = 0x7FFFFFFF;
-  if (const ConstantArrayType *CAT = DeclType->getAsConstantArrayType()) {
+  if (const ConstantArrayType *CAT =
+        SemaRef->Context.getAsConstantArrayType(DeclType)) {
     maxElements = static_cast<int>(CAT->getSize().getZExtValue());
   }
   return maxElements;
@@ -231,7 +232,8 @@
       return;
     }
   }
-  if (const VariableArrayType *VAT = DeclType->getAsVariableArrayType()) {
+  if (const VariableArrayType *VAT =
+        SemaRef->Context.getAsVariableArrayType(DeclType)) {
     // Check for VLAs; in standard C it would be possible to check this
     // earlier, but I don't know where clang accepts VLAs (gcc accepts
     // them in all sorts of strange places).
@@ -243,7 +245,8 @@
   }
 
   int maxElements = numArrayElements(DeclType);
-  QualType elementType = DeclType->getAsArrayType()->getElementType();
+  QualType elementType = SemaRef->Context.getAsArrayType(DeclType)
+                             ->getElementType();
   int numElements = 0;
   for (int i = 0; i < maxElements; ++i, ++numElements) {
     // Don't attempt to go past the end of the init list