Change EmitVLASize to take a QualType that must be a variably modified type.

Emit the size even if the declared type is a variably modified type. This lets us handle

void f(int n) {
  int (*a)[n];
  
  printf("size: %d\n", sizeof(*a));
}



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61285 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp
index 7f4e34d..e8084dc 100644
--- a/lib/CodeGen/CGDecl.cpp
+++ b/lib/CodeGen/CGDecl.cpp
@@ -160,9 +160,10 @@
         D.getStorageClass() == VarDecl::Register ? ".reg." : ".auto.";
       DeclPtr = GenerateStaticBlockVarDecl(D, true, Class);
     }
+    
+    if (Ty->isVariablyModifiedType())
+      EmitVLASize(Ty);
   } else {
-    const VariableArrayType *VAT = getContext().getAsVariableArrayType(Ty);
-
     if (!StackSaveValues.back()) {
       // Save the stack.
       const llvm::Type *LTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
@@ -180,7 +181,7 @@
     const llvm::Type *LElemPtrTy =
       llvm::PointerType::get(LElemTy, D.getType().getAddressSpace());
 
-    llvm::Value *VLASize = EmitVLASize(VAT);
+    llvm::Value *VLASize = EmitVLASize(Ty);
 
     // Allocate memory for the array.
     llvm::Value *VLA = Builder.CreateAlloca(llvm::Type::Int8Ty, VLASize, "vla");