From 2425cd815835fd941a65bda2d602ccc7216867ed Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Wed, 4 Jun 2008 19:41:28 +0000 Subject: [PATCH] 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. llvm-svn: 51960 --- clang/lib/CodeGen/CodeGenModule.cpp | 28 ++++++++++++++++------------ clang/test/CodeGen/typedef-func.c | 9 ++++++--- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 764186daf371..5be6872a1ecb 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -206,19 +206,23 @@ void CodeGenModule::SetFunctionAttributes(const FunctionDecl *FD, 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(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())); diff --git a/clang/test/CodeGen/typedef-func.c b/clang/test/CodeGen/typedef-func.c index 08328e67700d..c14a42c1e8ad 100644 --- a/clang/test/CodeGen/typedef-func.c +++ b/clang/test/CodeGen/typedef-func.c @@ -1,13 +1,16 @@ // RUN: clang -emit-llvm < %s // PR2414 -typedef void filter_func_t(); +struct mad_frame{}; +enum mad_flow {}; + +typedef enum mad_flow filter_func_t(void *, struct mad_frame *); + filter_func_t mono_filter; void addfilter2(filter_func_t *func){} void setup_filters() { - addfilter2( mono_filter); + addfilter2( mono_filter); } -