diff options
| author | Eli Friedman <eli.friedman@gmail.com> | 2008-06-04 19:41:28 +0000 | 
|---|---|---|
| committer | Eli Friedman <eli.friedman@gmail.com> | 2008-06-04 19:41:28 +0000 | 
| commit | 2425cd815835fd941a65bda2d602ccc7216867ed (patch) | |
| tree | 24333f94ce9ad027ffeeec1aeb6523af611f410f /clang/lib | |
| parent | 7bd6e58ddc9f91db4f9ce39eb953e00334f78fd2 (diff) | |
| download | bcm5719-llvm-2425cd815835fd941a65bda2d602ccc7216867ed.tar.gz bcm5719-llvm-2425cd815835fd941a65bda2d602ccc7216867ed.zip  | |
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
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 28 | 
1 files changed, 16 insertions, 12 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 764186daf37..5be6872a1ec 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<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()));  | 

