Clean up the CXXConstructExpr constructor, add Arg getters.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81178 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp
index c532b8c..86c5227 100644
--- a/lib/AST/ExprCXX.cpp
+++ b/lib/AST/ExprCXX.cpp
@@ -396,15 +396,22 @@
         CallExpr::hasAnyValueDependentArguments(args, numargs))),
   Constructor(D), Elidable(elidable), Args(0), NumArgs(numargs) {
     // leave room for default arguments;
-    FunctionDecl *FDecl = cast<FunctionDecl>(D);
-    unsigned NumArgsInProto = FDecl->param_size();
-    NumArgs += (NumArgsInProto - numargs);
-    if (NumArgs > 0) {
-      Args = new (C) Stmt*[NumArgs];
-      for (unsigned i = 0; i < numargs; ++i)
+    const FunctionProtoType *FTy = 
+      cast<FunctionDecl>(D)->getType()->getAsFunctionProtoType();
+    
+    unsigned NumArgsInProto = FTy->getNumArgs();
+    unsigned NumArgsToAllocate = FTy->isVariadic() ? NumArgs : NumArgsInProto;
+    if (NumArgsToAllocate) {
+      Args = new (C) Stmt*[NumArgsToAllocate];
+      
+      for (unsigned i = 0; i != NumArgs; ++i)
         Args[i] = args[i];
-      for (unsigned i = numargs; i < NumArgs; ++i)
+      
+      // Set default arguments to 0.
+      for (unsigned i = NumArgs; i != NumArgsToAllocate; ++i)
         Args[i] = 0;
+        
+      NumArgs = NumArgsToAllocate;
     }
 }