CMS 3D CMS Logo

FiniteMathChecker.cc
Go to the documentation of this file.
1 #include "FiniteMathChecker.h"
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>
7 
8 #include "CmsSupport.h"
9 #include <iostream>
10 #include <utility>
11 
12 namespace clangcms {
13 
14  void FiniteMathChecker::checkPreStmt(const clang::CallExpr *CE, clang::ento::CheckerContext &ctx) const {
15  const clang::ento::ProgramStateRef state = ctx.getState();
16  const clang::LocationContext *LC = ctx.getLocationContext();
17  const clang::Expr *Callee = CE->getCallee();
18  const clang::FunctionDecl *FD = state->getSVal(Callee, LC).getAsFunctionDecl();
19 
20  if (!FD)
21  return;
22 
23  // Get the name of the callee.
24  clang::IdentifierInfo *II = FD->getIdentifier();
25  if (!II) // if no identifier, not a simple C function
26  return;
27 
28  if (!II->isStr("isnan") && !II->isStr("isinf"))
29  return;
30 
31  clang::ento::ExplodedNode *N = ctx.generateErrorNode();
32  if (!N)
33  return;
34 
35  if (!BT)
36  BT.reset(new clang::ento::BugType(this,
37  "std::isnan / std::isinf does not work when fast-math is used. Please use "
38  "edm::isNotFinite from 'FWCore/Utilities/interface/isFinite.h'",
39  "fastmath plugin"));
40 
41  std::unique_ptr<clang::ento::BugReport> report = llvm::make_unique<clang::ento::BugReport>(*BT, BT->getName(), N);
42  report->addRange(Callee->getSourceRange());
43  ctx.emitReport(std::move(report));
44  }
45 } // namespace clangcms
std::unique_ptr< clang::ento::BugType > BT
void checkPreStmt(const clang::CallExpr *ref, clang::ento::CheckerContext &C) const
#define N
Definition: blowfish.cc:9
def move(src, dest)
Definition: eostools.py:511