Skip to content

Commit

Permalink
EventSetupRecord::get static analyzer: Add calls to get made in non-m…
Browse files Browse the repository at this point in the history
…ember functions
  • Loading branch information
gartung committed Mar 12, 2021
1 parent 0ab3e70 commit e5efbd2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
14 changes: 13 additions & 1 deletion Utilities/StaticAnalyzers/src/ESRecordGetChecker.cpp
Expand Up @@ -45,7 +45,7 @@ namespace clangcms {
llvm::SmallString<100> buf;
llvm::raw_svector_ostream os(buf);
os << "function '";
llvm::dyn_cast<CXXMethodDecl>(D)->getNameForDiagnostic(os, Policy, true);
llvm::dyn_cast<FunctionDecl>(D)->getNameForDiagnostic(os, Policy, true);
os << "' ";
os << "calls function '";
MD->getNameForDiagnostic(os, Policy, true);
Expand Down Expand Up @@ -90,4 +90,16 @@ namespace clangcms {
return;
}

void ESRGetChecker::checkASTDecl(const FunctionDecl *FD, AnalysisManager &mgr, BugReporter &BR) const {
const SourceManager &SM = BR.getSourceManager();
PathDiagnosticLocation DLoc = PathDiagnosticLocation::createBegin(FD, SM);
if (SM.isInSystemHeader(DLoc.asLocation()) || SM.isInExternCSystemHeader(DLoc.asLocation()))
return;
if (!FD->doesThisDeclarationHaveABody())
return;
ESRWalker walker(this, BR, mgr.getAnalysisDeclContext(FD));
walker.Visit(FD->getBody());
return;
}

} // namespace clangcms
7 changes: 6 additions & 1 deletion Utilities/StaticAnalyzers/src/ESRecordGetChecker.h
Expand Up @@ -21,7 +21,8 @@
namespace clangcms {

class ESRGetChecker : public clang::ento::Checker<clang::ento::check::ASTDecl<clang::CXXMethodDecl>,
clang::ento::check::ASTDecl<clang::FunctionTemplateDecl> > {
clang::ento::check::ASTDecl<clang::FunctionTemplateDecl>,
clang::ento::check::ASTDecl<clang::FunctionDecl> > {
public:
void checkASTDecl(const clang::CXXMethodDecl *CMD,
clang::ento::AnalysisManager &mgr,
Expand All @@ -31,6 +32,10 @@ namespace clangcms {
clang::ento::AnalysisManager &mgr,
clang::ento::BugReporter &BR) const;

void checkASTDecl(const clang::FunctionDecl *CMD,
clang::ento::AnalysisManager &mgr,
clang::ento::BugReporter &BR) const;

private:
CmsException m_exception;
};
Expand Down

0 comments on commit e5efbd2

Please sign in to comment.