For setting attributes, don't assume there are ParamVarDecls available, 
because trying to access non-existent ParamVarDecls can crash. 
Testcase from the original source for PR2414.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51960 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index 764186d..5be6872 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -206,19 +206,23 @@
     ParamAttrList.push_back(
         llvm::ParamAttrsWithIndex::get(1, llvm::ParamAttr::StructRet));
   unsigned increment = AggregateReturn ? 2 : 1;
-  for (unsigned i = 0; i < FD->getNumParams(); i++) {
-    QualType ParamType = FD->getParamDecl(i)->getType();
-    unsigned ParamAttrs = 0;
-    if (ParamType->isRecordType())
-      ParamAttrs |= llvm::ParamAttr::ByVal;
-    if (ParamType->isSignedIntegerType() && ParamType->isPromotableIntegerType())
-      ParamAttrs |= llvm::ParamAttr::SExt;
-    if (ParamType->isUnsignedIntegerType() && ParamType->isPromotableIntegerType())
-      ParamAttrs |= llvm::ParamAttr::ZExt;
-    if (ParamAttrs)
-      ParamAttrList.push_back(llvm::ParamAttrsWithIndex::get(i + increment,
-                                                             ParamAttrs));
+  const FunctionTypeProto* FTP = dyn_cast<FunctionTypeProto>(FD->getType());
+  if (FTP) {
+    for (unsigned i = 0; i < FTP->getNumArgs(); i++) {
+      QualType ParamType = FTP->getArgType(i);
+      unsigned ParamAttrs = 0;
+      if (ParamType->isRecordType())
+        ParamAttrs |= llvm::ParamAttr::ByVal;
+      if (ParamType->isSignedIntegerType() && ParamType->isPromotableIntegerType())
+        ParamAttrs |= llvm::ParamAttr::SExt;
+      if (ParamType->isUnsignedIntegerType() && ParamType->isPromotableIntegerType())
+        ParamAttrs |= llvm::ParamAttr::ZExt;
+      if (ParamAttrs)
+        ParamAttrList.push_back(llvm::ParamAttrsWithIndex::get(i + increment,
+                                                               ParamAttrs));
+    }
   }
+
   F->setParamAttrs(llvm::PAListPtr::get(ParamAttrList.begin(),
                                         ParamAttrList.size()));