Skip to content

Commit

Permalink
Merge pull request #3585 from gartung/clang-34-comp
Browse files Browse the repository at this point in the history
Static Analyzer -- Fixes to work with clang 3.4 and clang 3.3
  • Loading branch information
ktf committed Apr 30, 2014
2 parents 40e489e + 5696f88 commit 1b32444
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
6 changes: 2 additions & 4 deletions Utilities/StaticAnalyzers/src/ClassChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ class WalkAST : public clang::StmtVisitor<WalkAST> {
AC(ac),
visitingCallExpr(0) {}



bool hasWork() const { return !WList.empty(); }

/// This method adds a CallExpr to the worklist
Expand Down Expand Up @@ -489,7 +487,7 @@ void WalkAST::ReportMember(const clang::MemberExpr *ME) {
std::string tolog = "data class '"+MD->getParent()->getNameAsString()+"' const function '" + support::getQualifiedName(*MD) + "' Warning: " + os.str();
if (!m_exception.reportClass( CELoc, BR ) ) return;
writeLog(tolog);
BR.EmitBasicReport(AC->getDecl(),"Class Checker : Member data modified in const function","ThreadSafety",os.str(),CELoc,R);
BR.EmitBasicReport(AC->getDecl(),"Class Checker : Member data modified in const function","ThreadSafety",os.str(),CELoc);
}

void WalkAST::ReportCall(const clang::CXXMemberCallExpr *CE) {
Expand Down Expand Up @@ -580,7 +578,7 @@ void WalkAST::ReportCallArg(const clang::CXXMemberCallExpr *CE,const int i) {

if (!m_exception.reportClass( ELoc, BR ) ) return;
writeLog(tolog);
BR.EmitBasicReport(CE->getCalleeDecl(),"Class Checker : Member data passed to non-const reference","ThreadSafety",os.str(),ELoc,L);
BR.EmitBasicReport(CE->getCalleeDecl(),"Class Checker : Member data passed to non-const reference","ThreadSafety",os.str(),ELoc);

}

Expand Down
31 changes: 29 additions & 2 deletions Utilities/StaticAnalyzers/src/FunctionDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,39 @@ class FDumper : public clang::StmtVisitor<FDumper> {
clang::ento::BugReporter &BR;
clang::AnalysisDeclContext *AC;

enum Kind { NotVisited,
Visited };

/// A DenseMap that records visited states of CallExpr.
llvm::DenseMap<const clang::Expr *, Kind> VisitedExpr;

public:
FDumper(clang::ento::BugReporter &br, clang::AnalysisDeclContext *ac )
: BR(br),
AC(ac) {}


/// This method adds a CallExpr to the worklist
void setVisited(Expr * E) {
Kind &K = VisitedExpr[E];
if ( K = NotVisited ) {
VisitedExpr[E] = Visited;
return;
}
}

bool wasVisited(Expr * E) {
Kind &K = VisitedExpr[E];
if ( K = Visited ) return true;
return false;
}

const clang::Stmt * ParentStmt(const Stmt *S) {
const Stmt * P = AC->getParentMap().getParentIgnoreParens(S);
if (!P) return 0;
return P;
}


void VisitChildren(clang::Stmt *S );
void VisitStmt( clang::Stmt *S) { VisitChildren(S); }
void VisitCallExpr( CallExpr *CE );
Expand All @@ -43,6 +64,8 @@ void FDumper::VisitChildren( clang::Stmt *S) {
}

void FDumper::VisitCXXConstructExpr( CXXConstructExpr *CCE ) {
// if (wasVisited(CCE)) return;
// setVisited(CCE);
LangOptions LangOpts;
LangOpts.CPlusPlus = true;
PrintingPolicy Policy(LangOpts);
Expand All @@ -61,11 +84,14 @@ void FDumper::VisitCXXConstructExpr( CXXConstructExpr *CCE ) {
tname+="/tmp/function-dumper.txt.unsorted";
std::string ostring = "function '"+ mdname + "' " + "calls function '" + mname + "'\n";
std::ofstream file(tname.c_str(),std::ios::app);
file<<ostring;
file<<ostring;
VisitChildren(CCE);
}


void FDumper::VisitCallExpr( CallExpr *CE ) {
// if (wasVisited(CE)) return;
// setVisited(CE);
LangOptions LangOpts;
LangOpts.CPlusPlus = true;
PrintingPolicy Policy(LangOpts);
Expand All @@ -86,6 +112,7 @@ void FDumper::VisitCallExpr( CallExpr *CE ) {
std::ofstream file(tname.c_str(),std::ios::app);
file<<ostring;
Visit(CE->getCallee()->IgnoreParens());
VisitChildren(CE);
}

void FunctionDumper::checkASTDecl(const CXXMethodDecl *MD, AnalysisManager& mgr,
Expand Down
2 changes: 1 addition & 1 deletion Utilities/StaticAnalyzers/src/edmChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void edmChecker::checkASTDecl(const clang::CXXRecordDecl *RD, clang::ento::Analy
}
clang::ento::PathDiagnosticLocation ELoc =clang::ento::PathDiagnosticLocation::createBegin( MD, SM );
clang::SourceLocation SL = MD->getLocStart();
BR.EmitBasicReport(MD, "Class Checker : inherits from edm::EDProducer or edm::EDFilter","optional",os.str(),ELoc,SL);
BR.EmitBasicReport(MD, "Class Checker : inherits from edm::EDProducer or edm::EDFilter","optional",os.str(),ELoc);
}
}
}
Expand Down

0 comments on commit 1b32444

Please sign in to comment.