예제 #1
0
void CatchAll::checkASTCodeBody(const clang::Decl* D, clang::ento::AnalysisManager& AM, clang::ento::BugReporter& BR) const
{
  const clang::Stmt* s=D->getBody();
  if (!s) return;
  s=process(s);
  if (!s) return;
  clang::ento::LocationOrAnalysisDeclContext x(AM.getAnalysisDeclContext(D));
  clang::ento::PathDiagnosticLocation DLoc = clang::ento::PathDiagnosticLocation::createBegin(s, BR.getSourceManager(),x);
  BR.EmitBasicReport(D, this, "'catch(...)' in sources","CMS code rules","using 'catch(...)' is forbidden", DLoc,s->getSourceRange ());
  
}
예제 #2
0
void getParamDumper::checkASTDecl(const clang::CXXRecordDecl *RD, clang::ento::AnalysisManager& mgr, clang::ento::BugReporter &BR) const {
  

     const clang::SourceManager &SM = BR.getSourceManager();
     const char *sfile=SM.getPresumedLoc(RD->getLocation()).getFilename();
     if (!support::isCmsLocalFile(sfile)) return;

     std::string tname = "getparam-dumper.txt.unsorted";
     std::string ps = "const class edm::ParameterSet ";
     std::string ups = "const class edm::UntrackedParameterSet ";

     for (clang::CXXRecordDecl::ctor_iterator
          I = RD->ctor_begin(), E = RD->ctor_end(); I != E; ++I)  {
          clang::CXXConstructorDecl * CD = llvm::dyn_cast<clang::CXXConstructorDecl>((*I)->getMostRecentDecl());
          for ( unsigned I=0, E=CD->getNumParams(); I != E; ++I) {
              std::string pname = CD->getParamDecl(I)->getQualifiedNameAsString();
              std::string qname = CD->getParamDecl(I)->getType().getCanonicalType().getAsString();
              if (qname.substr(0,ps.length()) == ps || qname.substr(0,ups.length()) == ups) {
                   std::string buf;
                   llvm::raw_string_ostream os(buf);
                   os << "constructor decl '"<<CD->getQualifiedNameAsString()<< "' with parameter '"<< qname << " " << pname <<"'\n";
                   support::writeLog(os.str(),tname);
                   for ( CXXConstructorDecl::init_iterator J = CD->init_begin(), E=CD->init_end(); J != E; ++J ) {
                      if (FieldDecl * fd = (*J)->getAnyMember()) {
                          std::string fname = fd->getQualifiedNameAsString();
                          std::string fqname = fd->getType().getCanonicalType().getAsString();
                          os << "constructor decl '"<<CD->getQualifiedNameAsString()<< "' initializer for member decl '" << fname << "' of type '" <<fqname<<"'\n";
                          Expr * e = (*J)->getInit();
                          if ( e ) {
                              gpWalkAST walker(this,BR, mgr.getAnalysisDeclContext(CD),fd);
                              walker.Visit(e);
                              }
                          }
                   }
                   support::writeLog(os.str(),tname);
              }
         }
     }

     for (clang::CXXRecordDecl::method_iterator
          I = RD->method_begin(), E = RD->method_end(); I != E; ++I)  {
          clang::CXXMethodDecl * MD = llvm::cast<clang::CXXMethodDecl>((*I)->getMostRecentDecl());
          for ( unsigned I=0, E=MD->getNumParams(); I != E; ++I) {
              std::string pname = MD->getParamDecl(I)->getQualifiedNameAsString();
              std::string qname = MD->getParamDecl(I)->getType().getCanonicalType().getAsString();
              if (qname.substr(0,ps.length()) == ps || qname.substr(0,ups.length()) == ups) {
                   std::string buf;
                   llvm::raw_string_ostream os(buf);
                   clang::Stmt *Body = MD->getBody();
                   if ( Body ) {
                       os << "function decl '"<<MD->getQualifiedNameAsString()<< "' with parameter '"<< qname << " " << pname <<"'\n";
                       gpWalkAST walker(this,BR, mgr.getAnalysisDeclContext(MD),MD);
                       walker.Visit(Body);
                  }
                  support::writeLog(os.str(),tname);
             }
          }
      }   

  return;
}