CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/Utilities/StaticAnalyzers/src/FiniteMathChecker.cc

Go to the documentation of this file.
00001 #include "FiniteMathChecker.h"
00002 #include <clang/AST/AST.h>
00003 #include <clang/AST/ASTConsumer.h>
00004 #include <clang/AST/DeclGroup.h>
00005 #include <clang/AST/RecursiveASTVisitor.h>
00006 #include <clang/AST/Expr.h>
00007 
00008 
00009 #include "CmsSupport.h"
00010 #include <iostream>
00011 
00012 namespace clangcms {
00013 
00014 void FiniteMathChecker::checkPreStmt(const clang::CallExpr *CE, clang::ento::CheckerContext &ctx) const
00015 {
00016   const clang::ento::ProgramStateRef state = ctx.getState();
00017   const clang::LocationContext *LC = ctx.getLocationContext();
00018   const clang::Expr *Callee = CE->getCallee();
00019   const clang::FunctionDecl *FD = state->getSVal(Callee, LC).getAsFunctionDecl();
00020 
00021   if (!FD)
00022     return;
00023 
00024   // Get the name of the callee.
00025   clang::IdentifierInfo *II = FD->getIdentifier();
00026   if (!II)   // if no identifier, not a simple C function
00027     return;
00028 
00029   if (!II->isStr("isnan") && !II->isStr("isinf")) 
00030     return;
00031 
00032   clang::ento::ExplodedNode *N = ctx.generateSink();
00033   if (!N)
00034     return;
00035 
00036   if (!BT)
00037     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"));
00038 
00039   clang::ento::BugReport *report = new clang::ento::BugReport(*BT, BT->getName(), N);
00040   report->addRange(Callee->getSourceRange());
00041   ctx.emitReport(report);
00042 }
00043 }
00044