CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
9 #include "CmsSupport.h"
10 #include <iostream>
11 
12 namespace clangcms {
13 
14 void FiniteMathChecker::checkPreStmt(const clang::CallExpr *CE, clang::ento::CheckerContext &ctx) const
15 {
16  const clang::ento::ProgramStateRef state = ctx.getState();
17  const clang::LocationContext *LC = ctx.getLocationContext();
18  const clang::Expr *Callee = CE->getCallee();
19  const clang::FunctionDecl *FD = state->getSVal(Callee, LC).getAsFunctionDecl();
20 
21  if (!FD)
22  return;
23 
24  // Get the name of the callee.
25  clang::IdentifierInfo *II = FD->getIdentifier();
26  if (!II) // if no identifier, not a simple C function
27  return;
28 
29  if (!II->isStr("isnan") && !II->isStr("isinf"))
30  return;
31 
32  clang::ento::ExplodedNode *N = ctx.generateSink();
33  if (!N)
34  return;
35 
36  if (!BT)
37  BT.reset(new clang::ento::BugType("std::isnan / std::isinf does not work when fast-math is used. Please use edm::isNotFinite from 'FWCore/Utilities/interface/isNotFinite.h'", "fastmath plugin"));
38 
39  clang::ento::BugReport *report = new clang::ento::BugReport(*BT, BT->getName(), N);
40  report->addRange(Callee->getSourceRange());
41  ctx.emitReport(report);
42 }
43 }
44 
llvm::OwningPtr< clang::ento::BugType > BT
tuple report
Definition: zeeHLT_cff.py:9
void checkPreStmt(const clang::CallExpr *ref, clang::ento::CheckerContext &C) const
#define N
Definition: blowfish.cc:9
char state
Definition: procUtils.cc:75