Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:32:05

0001 #include "FiniteMathChecker.h"
0002 #include <clang/AST/AST.h>
0003 #include <clang/AST/ASTConsumer.h>
0004 #include <clang/AST/DeclGroup.h>
0005 #include <clang/AST/RecursiveASTVisitor.h>
0006 #include <clang/AST/Expr.h>
0007 
0008 #include "CmsSupport.h"
0009 #include <iostream>
0010 #include <memory>
0011 
0012 #include <utility>
0013 
0014 namespace clangcms {
0015 
0016   void FiniteMathChecker::checkPreStmt(const clang::CallExpr *CE, clang::ento::CheckerContext &ctx) const {
0017     const clang::ento::ProgramStateRef state = ctx.getState();
0018     const clang::LocationContext *LC = ctx.getLocationContext();
0019     const clang::Expr *Callee = CE->getCallee();
0020     const clang::FunctionDecl *FD = state->getSVal(Callee, LC).getAsFunctionDecl();
0021 
0022     if (!FD)
0023       return;
0024 
0025     // Get the name of the callee.
0026     clang::IdentifierInfo *II = FD->getIdentifier();
0027     if (!II)  // if no identifier, not a simple C function
0028       return;
0029 
0030     if (!II->isStr("isnan") && !II->isStr("isinf"))
0031       return;
0032 
0033     clang::ento::ExplodedNode *N = ctx.generateErrorNode();
0034     if (!N)
0035       return;
0036 
0037     if (!BT)
0038       BT = std::make_unique<clang::ento::BugType>(
0039           this,
0040           "std::isnan / std::isinf does not work when fast-math is used. Please use "
0041           "edm::isNotFinite from 'FWCore/Utilities/interface/isFinite.h'",
0042           "fastmath plugin");
0043     std::unique_ptr<clang::ento::PathSensitiveBugReport> PSBR =
0044         std::make_unique<clang::ento::PathSensitiveBugReport>(*BT, BT->getCheckerName(), N);
0045     std::unique_ptr<clang::ento::BasicBugReport> report =
0046         std::make_unique<clang::ento::BasicBugReport>(*BT, BT->getCheckerName(), PSBR->getLocation());
0047     report->addRange(Callee->getSourceRange());
0048     ctx.emitReport(std::move(report));
0049   }
0050 }  // namespace clangcms