Skip to content

Commit

Permalink
Merge pull request #1850 from gartung/clang-update42
Browse files Browse the repository at this point in the history
Tools updates -- Clang updates
  • Loading branch information
ktf committed Dec 17, 2013
2 parents 791f676 + 2fe9905 commit 13af5ef
Show file tree
Hide file tree
Showing 10 changed files with 3,165 additions and 827 deletions.
1,317 changes: 598 additions & 719 deletions Utilities/StaticAnalyzers/scripts/classes.txt

Large diffs are not rendered by default.

792 changes: 792 additions & 0 deletions Utilities/StaticAnalyzers/scripts/classes.txt.dumperct

Large diffs are not rendered by default.

1,083 changes: 1,083 additions & 0 deletions Utilities/StaticAnalyzers/scripts/classes.txt.dumperft

Large diffs are not rendered by default.

524 changes: 524 additions & 0 deletions Utilities/StaticAnalyzers/scripts/classes.txt.inherits

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Utilities/StaticAnalyzers/scripts/run_class_dumper.sh
Expand Up @@ -13,15 +13,15 @@ eval `scram runtime -sh`
ulimit -m 2000000
ulimit -v 2000000
ulimit -t 1200
for file in `cmsglimpse -l -F src/classes.h$ include`;do dir=`dirname $file`;echo \#include \<$file\> >${CMSSW_BASE}/src/$dir/classes_def.cc ; done
for file in `cmsglimpse -l -F src/classes.*.h$ include`;do dir=`dirname $file`;echo \#include \<$file\> >${CMSSW_BASE}/src/$dir/`basename $file`.cc ; done
export USER_LLVM_CHECKERS="-disable-checker cplusplus -disable-checker unix -disable-checker threadsafety -disable-checker core -disable-checker security -disable-checker deadcode -disable-checker cms -enable-checker optional.ClassDumperCT -disable-checker optional.ClassDumperFT"
scram b -k -j $J checker
sort -u ${CMSSW_BASE}/tmp/classes.txt.dumperct.unsorted |grep -v -e"^class std::">${CMSSW_BASE}/tmp/classes.txt.dumperct
find ${CMSSW_BASE}/src/ -name classes_def.cc | xargs rm -f
sort -u ${CMSSW_BASE}/tmp/classes.txt.dumperct.unsorted >${CMSSW_BASE}/tmp/classes.txt.dumperct
find ${CMSSW_BASE}/src/ -name classes\*.h.cc | xargs rm -f
export USER_LLVM_CHECKERS="-disable-checker cplusplus -disable-checker unix -disable-checker threadsafety -disable-checker core -disable-checker security -disable-checker deadcode -disable-checker cms -disable-checker optional.ClassDumperCT -enable-checker optional.ClassDumperFT"
scram b -k -j $J checker
sort -u ${CMSSW_BASE}/tmp/classes.txt.dumperft.unsorted |grep -v -e"^class std::">${CMSSW_BASE}/tmp/classes.txt.dumperft
sort -u ${CMSSW_BASE}/tmp/classes.txt.dumperft.unsorted >${CMSSW_BASE}/tmp/classes.txt.dumperft
export USER_LLVM_CHECKERS="-disable-checker cplusplus -disable-checker unix -disable-checker threadsafety -disable-checker core -disable-checker security -disable-checker deadcode -disable-checker cms -enable-checker optional.ClassDumperInherit"
scram b -k -j $J checker
sort -u ${CMSSW_BASE}/tmp/classes.txt.inherits.unsorted |grep -v -e"^class std::">${CMSSW_BASE}/tmp/classes.txt.inherits
sort -u ${CMSSW_BASE}/tmp/classes.txt.inherits.unsorted >${CMSSW_BASE}/tmp/classes.txt.inherits
cat ${CMSSW_BASE}/tmp/classes.txt.dumperct ${CMSSW_BASE}/tmp/classes.txt.dumperft ${CMSSW_BASE}/tmp/classes.txt.inherits | sort -u >${CMSSW_BASE}/tmp/classes.txt
46 changes: 39 additions & 7 deletions Utilities/StaticAnalyzers/src/ClassChecker.cpp
Expand Up @@ -30,13 +30,36 @@
#include <llvm/ADT/SmallString.h>

#include "ClassChecker.h"
#include <boost/interprocess/sync/interprocess_semaphore.hpp>
#include <iostream>
#include <fstream>
#include <iterator>
#include <string>
#include <algorithm>

using namespace clang;
using namespace clang::ento;
using namespace llvm;

namespace clangcms {

[[edm::thread_safe]] static boost::interprocess::interprocess_semaphore file_mutex(1);

void writeLog(std::string ostring) {
const char * pPath = std::getenv("LOCALRT");
std::string tname = "";
if ( pPath != NULL ) tname += std::string(pPath);
tname+="/tmp/class-checker.txt.unsorted";
std::fstream file(tname.c_str(),std::ios::in|std::ios::out|std::ios::app);
std::string filecontents((std::istreambuf_iterator<char>(file)),std::istreambuf_iterator<char>() );
if ( filecontents.find(ostring) == std::string::npos ) file<<ostring;
file.flush();
file.close();
return;
}



class WalkAST : public clang::StmtVisitor<WalkAST> {
clang::ento::BugReporter &BR;
clang::AnalysisDeclContext *AC;
Expand Down Expand Up @@ -150,7 +173,6 @@ class WalkAST : public clang::StmtVisitor<WalkAST> {




void WalkAST::VisitChildren( clang::Stmt *S) {
for (clang::Stmt::child_iterator I = S->child_begin(), E = S->child_end(); I!=E; ++I)
if (clang::Stmt *child = *I) {
Expand Down Expand Up @@ -279,7 +301,7 @@ void WalkAST::VisitDeclRefExpr( clang::DeclRefExpr * DRE) {
}

void WalkAST::ReportDeclRef( const clang::DeclRefExpr * DRE) {

if (const clang::VarDecl * D = llvm::dyn_cast<clang::VarDecl>(DRE->getDecl())) {
clang::QualType t = D->getType();
const clang::Stmt * PS = ParentStmt(DRE);
Expand All @@ -300,6 +322,7 @@ void WalkAST::ReportDeclRef( const clang::DeclRefExpr * DRE) {
os << "Non-const variable '" << D->getNameAsString() << "' is static local and accessed in statement '";
PS->printPretty(os,0,Policy);
os << "'.\n";
writeLog(os.str());
BugType * BT = new BugType("ClassChecker : non-const static local variable accessed","ThreadSafety");
BugReport * R = new BugReport(*BT,os.str(),CELoc);
BR.emitReport(R);
Expand All @@ -313,6 +336,7 @@ void WalkAST::ReportDeclRef( const clang::DeclRefExpr * DRE) {
os << "Non-const variable '" << D->getNameAsString() << "' is static member data and accessed in statement '";
PS->printPretty(os,0,Policy);
os << "'.\n";
writeLog(os.str());
BugType * BT = new BugType("ClassChecker : non-const static member variable accessed","ThreadSafety");
BugReport * R = new BugReport(*BT,os.str(),CELoc);
BR.emitReport(R);
Expand All @@ -331,6 +355,7 @@ void WalkAST::ReportDeclRef( const clang::DeclRefExpr * DRE) {
os << "Non-const variable '" << D->getNameAsString() << "' is global static and accessed in statement '";
PS->printPretty(os,0,Policy);
os << "'.\n";
writeLog(os.str());
BugType * BT = new BugType("ClassChecker : non-const global static variable accessed","ThreadSafety");
BugReport * R = new BugReport(*BT,os.str(),CELoc);
BR.emitReport(R);
Expand Down Expand Up @@ -423,35 +448,40 @@ void WalkAST::ReportMember(const clang::MemberExpr *ME) {
CELoc = clang::ento::PathDiagnosticLocation::createBegin(ME, BR.getSourceManager(),AC);
R = ME->getSourceRange();

os << " Member data '";
os << "Member data '";
ME->printPretty(os,0,Policy);
os << "' is directly or indirectly modified in const function";
os << "' is directly or indirectly modified in const function\n";

if (!m_exception.reportClass( CELoc, BR ) ) return;
writeLog(os.str());
BR.EmitBasicReport(AC->getDecl(),"Class Checker : Member data modified in const function","ThreadSafety",os.str(),CELoc,R);
}

void WalkAST::ReportCall(const clang::CXXMemberCallExpr *CE) {

if ( support::isSafeClassName( CE->getRecordDecl()->getQualifiedNameAsString() ) ) return;
llvm::SmallString<100> buf;
llvm::raw_svector_ostream os(buf);

CmsException m_exception;
clang::LangOptions LangOpts;
LangOpts.CPlusPlus = true;
clang::PrintingPolicy Policy(LangOpts);


CE->printPretty(os,0,Policy);
os<<"' is a non-const member function that could modify member data object '";
CE->getImplicitObjectArgument()->printPretty(os,0,Policy);
os << "\n";
clang::ento::PathDiagnosticLocation CELoc =
clang::ento::PathDiagnosticLocation::createBegin(CE, BR.getSourceManager(),AC);


if (!m_exception.reportClass( CELoc, BR ) ) return;
writeLog(os.str());
BugType * BT = new BugType("Class Checker : Non-const member function could modify member data object","ThreadSafety");
BugReport * R = new BugReport(*BT,os.str(),CELoc);
BR.emitReport(R);



}
Expand Down Expand Up @@ -502,6 +532,7 @@ void WalkAST::ReportCallArg(const clang::CXXMemberCallExpr *CE,const int i) {
os << " Member data " << VD->getQualifiedNameAsString();
os<< " is passed to a non-const reference parameter";
os <<" of CXX method '" << MD->getQualifiedNameAsString() << "in const function";
os << "\n";


clang::ento::PathDiagnosticLocation ELoc =
Expand All @@ -525,6 +556,7 @@ void WalkAST::ReportCallReturn(const clang::ReturnStmt * RS) {
os << "Returns a pointer or reference to a non-const member data object ";
os << "in const function in statement '";
RS->printPretty(os,0,Policy);
os << "\n";


clang::ento::PathDiagnosticLocation CELoc =
Expand Down Expand Up @@ -577,7 +609,8 @@ void ClassChecker::checkASTDecl(const clang::CXXRecordDecl *RD, clang::ento::Ana
{
llvm::SmallString<100> buf;
llvm::raw_svector_ostream os(buf);
os << MD->getQualifiedNameAsString() << " is a const member function that returns a pointer or reference to a non-const object";
os << MD->getQualifiedNameAsString() << " is a const member function that returns a pointer or reference to a non-const object \n";
writeLog(os.str());
clang::SourceRange SR = MD->getSourceRange();
BR.EmitBasicReport(MD, "Class Checker : Const function returns pointer or reference to non-const object.","ThreadSafety",os.str(),ELoc);
}
Expand All @@ -587,5 +620,4 @@ void ClassChecker::checkASTDecl(const clang::CXXRecordDecl *RD, clang::ento::Ana

} //end of class


} //end namespace

0 comments on commit 13af5ef

Please sign in to comment.