When instantiating a function that was declared via a typedef, e.g.,

    typedef int functype(int, int);
    functype func;

also instantiate the synthesized function parameters for the resulting
function declaration. 

With this change, Boost.Wave builds and passes all of its regression
tests.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103025 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp
index 4963e73..48ae511 100644
--- a/lib/CodeGen/CGDebugInfo.cpp
+++ b/lib/CodeGen/CGDebugInfo.cpp
@@ -495,7 +495,10 @@
 llvm::DIType
 CGDebugInfo::getOrCreateMethodType(const CXXMethodDecl *Method,
                                    llvm::DIFile Unit) {
-  llvm::DIType FnTy = getOrCreateType(Method->getType(), Unit);
+  llvm::DIType FnTy
+    = getOrCreateType(QualType(Method->getType()->getAs<FunctionProtoType>(),
+                               0),
+                      Unit);
   
   // Static methods do not need "this" pointer argument.
   if (Method->isStatic())
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 0e839a9..a802679 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -3243,8 +3243,10 @@
     for (FunctionProtoType::arg_type_iterator AI = FT->arg_type_begin(),
          AE = FT->arg_type_end(); AI != AE; ++AI) {
       ParmVarDecl *Param = ParmVarDecl::Create(Context, NewFD,
-                                               SourceLocation(), 0,
-                                               *AI, /*TInfo=*/0,
+                                               D.getIdentifierLoc(), 0,
+                                               *AI, 
+                                         Context.getTrivialTypeSourceInfo(*AI, 
+                                                          D.getIdentifierLoc()),
                                                VarDecl::None,
                                                VarDecl::None, 0);
       Param->setImplicit();
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index c4ab03f..869d6df 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -3565,8 +3565,8 @@
     if (BinaryOperator *BO = dyn_cast<BinaryOperator>(NakedFn)) {
       if (BO->getOpcode() == BinaryOperator::PtrMemD ||
           BO->getOpcode() == BinaryOperator::PtrMemI) {
-        if (const FunctionProtoType *FPT =
-              dyn_cast<FunctionProtoType>(BO->getType())) {
+        if (const FunctionProtoType *FPT
+                                = BO->getType()->getAs<FunctionProtoType>()) {
           QualType ResultTy = FPT->getResultType().getNonReferenceType();
 
           ExprOwningPtr<CXXMemberCallExpr>
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index 21f2a51..b87fa7d 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -6513,7 +6513,7 @@
   MemExpr->setBase(ObjectArg);
 
   // Convert the rest of the arguments
-  const FunctionProtoType *Proto = cast<FunctionProtoType>(Method->getType());
+  const FunctionProtoType *Proto = Method->getType()->getAs<FunctionProtoType>();
   if (ConvertArgumentsForCall(&*TheCall, MemExpr, Method, Proto, Args, NumArgs,
                               RParenLoc))
     return ExprError();
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 8b851b2..da84806 100644
--- a/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1169,6 +1169,27 @@
     return 0;
   QualType T = TInfo->getType();
 
+  // \brief If the type of this function is not *directly* a function
+  // type, then we're instantiating the a function that was declared
+  // via a typedef, e.g.,
+  //
+  //   typedef int functype(int, int);
+  //   functype func;
+  //
+  // In this case, we'll just go instantiate the ParmVarDecls that we
+  // synthesized in the method declaration.
+  if (!isa<FunctionProtoType>(T)) {
+    assert(!Params.size() && "Instantiating type could not yield parameters");
+    for (unsigned I = 0, N = D->getNumParams(); I != N; ++I) {
+      ParmVarDecl *P = SemaRef.SubstParmVarDecl(D->getParamDecl(I), 
+                                                TemplateArgs);
+      if (!P)
+        return 0;
+
+      Params.push_back(P);
+    }
+  }
+
   NestedNameSpecifier *Qualifier = D->getQualifier();
   if (Qualifier) {
     Qualifier = SemaRef.SubstNestedNameSpecifier(Qualifier,