Use the "undergoes default argument promotion" bit on parameters to
simplify the logic of initializing function parameters so that we don't need
both a variable declaration and a type in FunctionArgList.  This also means
that we need to propagate the CGFunctionInfo down in a lot of places rather
than recalculating it from the FAL.  There's more we can do to eliminate
redundancy here, and I've left FIXMEs behind to do it.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127314 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp
index 50e03cd..fa98f0d 100644
--- a/lib/CodeGen/CodeGenFunction.cpp
+++ b/lib/CodeGen/CodeGenFunction.cpp
@@ -210,6 +210,7 @@
 
 void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
                                     llvm::Function *Fn,
+                                    const CGFunctionInfo &FnInfo,
                                     const FunctionArgList &Args,
                                     SourceLocation StartLoc) {
   const Decl *D = GD.getDecl();
@@ -218,6 +219,7 @@
   CurCodeDecl = CurFuncDecl = D;
   FnRetTy = RetTy;
   CurFn = Fn;
+  CurFnInfo = &FnInfo;
   assert(CurFn->isDeclaration() && "Function already has body?");
 
   // Pass inline keyword to optimizer if it appears explicitly on any
@@ -275,11 +277,6 @@
   if (CGM.getCodeGenOpts().InstrumentForProfiling)
     EmitMCountInstrumentation();
 
-  // FIXME: Leaked.
-  // CC info is ignored, hopefully?
-  CurFnInfo = &CGM.getTypes().getFunctionInfo(FnRetTy, Args,
-                                              FunctionType::ExtInfo());
-
   if (RetTy->isVoidType()) {
     // Void type; nothing to return.
     ReturnValue = 0;
@@ -302,7 +299,7 @@
   // emit the type size.
   for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end();
        i != e; ++i) {
-    QualType Ty = i->second;
+    QualType Ty = (*i)->getType();
 
     if (Ty->isVariablyModifiedType())
       EmitVLASize(Ty);
@@ -332,7 +329,8 @@
   F->setDoesNotThrow(true);
 }
 
-void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn) {
+void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn,
+                                   const CGFunctionInfo &FnInfo) {
   const FunctionDecl *FD = cast<FunctionDecl>(GD.getDecl());
   
   // Check if we should generate debug info for this function.
@@ -346,20 +344,15 @@
   if (isa<CXXMethodDecl>(FD) && cast<CXXMethodDecl>(FD)->isInstance())
     CGM.getCXXABI().BuildInstanceFunctionParams(*this, ResTy, Args);
 
-  if (FD->getNumParams()) {
-    const FunctionProtoType* FProto = FD->getType()->getAs<FunctionProtoType>();
-    assert(FProto && "Function def must have prototype!");
-
+  if (FD->getNumParams())
     for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i)
-      Args.push_back(std::make_pair(FD->getParamDecl(i),
-                                    FProto->getArgType(i)));
-  }
+      Args.push_back(FD->getParamDecl(i));
 
   SourceRange BodyRange;
   if (Stmt *Body = FD->getBody()) BodyRange = Body->getSourceRange();
 
   // Emit the standard function prologue.
-  StartFunction(GD, ResTy, Fn, Args, BodyRange.getBegin());
+  StartFunction(GD, ResTy, Fn, FnInfo, Args, BodyRange.getBegin());
 
   // Generate the body of the function.
   if (isa<CXXDestructorDecl>(FD))