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