diff options
author | Devin Coughlin <dcoughlin@apple.com> | 2016-11-15 18:40:46 +0000 |
---|---|---|
committer | Devin Coughlin <dcoughlin@apple.com> | 2016-11-15 18:40:46 +0000 |
commit | 8693adfd4669a9080d12ca42a4c9ab8661be6062 (patch) | |
tree | a7bb525e0a4414955189c84de7d7b2849fd7af6f /clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp | |
parent | 34652925cbb0316c632975ae070649db5958a457 (diff) | |
download | bcm5719-llvm-8693adfd4669a9080d12ca42a4c9ab8661be6062.tar.gz bcm5719-llvm-8693adfd4669a9080d12ca42a4c9ab8661be6062.zip |
[analyzer] Add check for when block is called with too few arguments.
The CallAndMessageChecker has an existing check for when a function pointer
is called with too few arguments. Extend this logic to handle the block
case, as well. While we're at it, do a drive-by grammar correction
("less" --> "fewer") on the diagnostic text.
llvm-svn: 287001
Diffstat (limited to 'clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp')
-rw-r--r-- | clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp index 5126716fcde..f474857a1bf 100644 --- a/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp @@ -356,7 +356,6 @@ void CallAndMessageChecker::checkPreStmt(const CXXDeleteExpr *DE, } } - void CallAndMessageChecker::checkPreCall(const CallEvent &Call, CheckerContext &C) const { ProgramStateRef State = C.getState(); @@ -389,11 +388,10 @@ void CallAndMessageChecker::checkPreCall(const CallEvent &Call, } const Decl *D = Call.getDecl(); - const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D); - if (FD) { - // If we have a declaration, we can make sure we pass enough parameters to - // the function. - unsigned Params = FD->getNumParams(); + if (D && (isa<FunctionDecl>(D) || isa<BlockDecl>(D))) { + // If we have a function or block declaration, we can make sure we pass + // enough parameters. + unsigned Params = Call.parameters().size(); if (Call.getNumArgs() < Params) { ExplodedNode *N = C.generateErrorNode(); if (!N) @@ -403,8 +401,14 @@ void CallAndMessageChecker::checkPreCall(const CallEvent &Call, SmallString<512> Str; llvm::raw_svector_ostream os(Str); - os << "Function taking " << Params << " argument" - << (Params == 1 ? "" : "s") << " is called with less (" + if (isa<FunctionDecl>(D)) { + os << "Function "; + } else { + assert(isa<BlockDecl>(D)); + os << "Block "; + } + os << "taking " << Params << " argument" + << (Params == 1 ? "" : "s") << " is called with fewer (" << Call.getNumArgs() << ")"; C.emitReport( @@ -425,6 +429,7 @@ void CallAndMessageChecker::checkPreCall(const CallEvent &Call, else BT = &BT_call_arg; + const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D); for (unsigned i = 0, e = Call.getNumArgs(); i != e; ++i) { const ParmVarDecl *ParamDecl = nullptr; if(FD && i < FD->getNumParams()) |