2 #include <clang/AST/AST.h> 3 #include <clang/AST/ASTConsumer.h> 4 #include <clang/AST/DeclGroup.h> 5 #include <clang/AST/RecursiveASTVisitor.h> 6 #include <clang/AST/Expr.h> 14 using namespace clang;
20 class FMWalkAST :
public clang::StmtVisitor<FMWalkAST> {
22 clang::ento::BugReporter &
BR;
23 clang::AnalysisDeclContext *
AC;
28 clang::ento::BugReporter &
br,
29 clang::AnalysisDeclContext *ac,
31 : Checker(checker), BR(
br), AC(ac), ND(nd) {}
34 void VisitChildren(clang::Stmt *
S);
36 void VisitCallExpr(clang::CallExpr *CE);
39 void FMWalkAST::VisitChildren(clang::Stmt *
S) {
40 for (clang::Stmt::child_iterator
I =
S->child_begin(), E =
S->child_end();
I != E; ++
I)
41 if (clang::Stmt *
child = *
I) {
46 void FMWalkAST::VisitCallExpr(clang::CallExpr *CE) {
47 const clang::Expr *Callee = CE->getCallee();
48 const FunctionDecl *FD = CE->getDirectCallee();
52 const char *sfile = BR.getSourceManager().getPresumedLoc(CE->getExprLoc()).getFilename();
58 clang::IdentifierInfo *II = FD->getIdentifier();
62 if (!II->isStr(
"isnan") && !II->isStr(
"isinf"))
65 clang::ento::PathDiagnosticLocation CELoc =
66 clang::ento::PathDiagnosticLocation::createBegin(CE, BR.getSourceManager(), AC);
67 BugType *BT =
new clang::ento::BugType(Checker,
68 "std::isnan / std::isinf does not work when fast-math is used. Please use " 69 "edm::isNotFinite from 'FWCore/Utilities/interface/isFinite.h'",
71 std::unique_ptr<clang::ento::BasicBugReport>
report =
72 std::make_unique<clang::ento::BasicBugReport>(*BT, BT->getCheckerName(), CELoc);
76 void FiniteMathChecker::checkASTDecl(
const clang::CXXRecordDecl *RD,
77 clang::ento::AnalysisManager &mgr,
78 clang::ento::BugReporter &BR)
const {
79 const clang::SourceManager &SM = BR.getSourceManager();
80 const char *sfile = SM.getPresumedLoc(RD->getLocation()).getFilename();
84 for (clang::CXXRecordDecl::method_iterator
I = RD->method_begin(), E = RD->method_end();
I != E; ++
I) {
85 clang::CXXMethodDecl *MD = llvm::cast<clang::CXXMethodDecl>((*I)->getMostRecentDecl());
86 clang::Stmt *Body = MD->getBody();
88 FMWalkAST walker(
this, BR, mgr.getAnalysisDeclContext(MD), MD);
void VisitStmt(clang::Stmt *S)
clang::AnalysisDeclContext * AC
bool isInterestingLocation(const std::string &d)
FMWalkAST(const CheckerBase *checker, clang::ento::BugReporter &br, clang::AnalysisDeclContext *ac, const NamedDecl *nd)
const CheckerBase * Checker
const std::complex< double > I
clang::ento::BugReporter & BR
bool isCmsLocalFile(const char *file)