aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/Decl.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-10-29 18:41:34 +0000
committerTed Kremenek <kremenek@apple.com>2008-10-29 18:41:34 +0000
commit4f03fd61ee45245dd3a1552a023e730d56c2e697 (patch)
tree4335a0af7e4fe0e3098cbb2d628bc0ebc05d2f53 /lib/AST/Decl.cpp
parent8e2f57ad06d73a6c2cacf0167a3b9e244439a9f9 (diff)
Fix crash reported in PR2923 where a function declared using typeof(another_function) would have FunctionDecl::getNumParams() return the number of parameters in the original function type and not the number of parameters in the actual FunctionDecl.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58392 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Decl.cpp')
-rw-r--r--lib/AST/Decl.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index 3713776298..dbc92f414f 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -176,16 +176,26 @@ Stmt *FunctionDecl::getBody(const FunctionDecl *&Definition) const {
return 0;
}
-unsigned FunctionDecl::getNumParams() const {
- const FunctionType *FT = getType()->getAsFunctionType();
+// Helper function for FunctionDecl::getNumParams and FunctionDecl::setParams()
+static unsigned getNumTypeParams(QualType T) {
+ const FunctionType *FT = T->getAsFunctionType();
if (isa<FunctionTypeNoProto>(FT))
return 0;
return cast<FunctionTypeProto>(FT)->getNumArgs();
}
+unsigned FunctionDecl::getNumParams() const {
+ // Can happen if a FunctionDecl is declared using typeof(some_other_func) bar;
+ if (!ParamInfo)
+ return 0;
+
+ return getNumTypeParams(getType());
+}
+
void FunctionDecl::setParams(ParmVarDecl **NewParamInfo, unsigned NumParams) {
assert(ParamInfo == 0 && "Already has param info!");
- assert(NumParams == getNumParams() && "Parameter count mismatch!");
+ assert(NumParams == getNumTypeParams(getType()) &&
+ "Parameter count mismatch!");
// Zero params -> null pointer.
if (NumParams) {