Skip to content

Commit

Permalink
Merge pull request #1476 from gartung/clang-FunctionChecker-filter-sa…
Browse files Browse the repository at this point in the history
…fe-statics

Static Analyzer  -- Filter out safe non-const global vars
  • Loading branch information
ktf committed Nov 18, 2013
2 parents d57191b + a43b941 commit 73b5702
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 10 additions & 1 deletion Utilities/StaticAnalyzers/src/FunctionChecker.cpp
Expand Up @@ -63,6 +63,15 @@ void FWalker::ReportDeclRef ( const clang::DeclRefExpr * DRE) {


if (const clang::VarDecl * D = llvm::dyn_cast<clang::VarDecl>(DRE->getDecl())) {

if ( support::isSafeClassName( D->getCanonicalDecl()->getQualifiedNameAsString() ) ) return;

const char *sfile=BR.getSourceManager().getPresumedLoc(D->getLocation()).getFilename();
std::string fname(sfile);
if ( fname.find("stdio.h") != std::string::npos
|| fname.find("iostream") != std::string::npos
|| fname.find("placeholders.hpp") != std::string::npos) return;

clang::QualType t = D->getType();
const Decl * PD = AC->getDecl();
std::string dname ="";
Expand All @@ -76,6 +85,7 @@ void FWalker::ReportDeclRef ( const clang::DeclRefExpr * DRE) {

if ( (D->isStaticLocal() && D->getTSCSpec() != clang::ThreadStorageClassSpecifier::TSCS_thread_local ) && ! clangcms::support::isConst( t ) )
{
if ( support::isSafeClassName( t.getAsString() ) ) return;
std::string buf;
llvm::raw_string_ostream os(buf);
os << "function '"<<dname << "' accesses or modifies non-const static local variable '" << D->getNameAsString() << "'.\n";
Expand All @@ -100,7 +110,6 @@ void FWalker::ReportDeclRef ( const clang::DeclRefExpr * DRE) {
!D->isStaticLocal() &&
!clangcms::support::isConst( t ) )
{

std::string buf;
llvm::raw_string_ostream os(buf);
os << "function '"<<dname << "' accesses or modifies non-const global static variable '" << D->getNameAsString() << "'.\n";
Expand Down
6 changes: 1 addition & 5 deletions Utilities/StaticAnalyzers/src/StaticLocalChecker.cpp
Expand Up @@ -24,11 +24,7 @@ void StaticLocalChecker::checkASTDecl(const clang::VarDecl *D,

if ( ! m_exception.reportGlobalStaticForType( t, DLoc, BR ) )
return;
std::string vname = D->getCanonicalDecl()->getQualifiedNameAsString();
unsigned found = vname.find_last_of("::");
std::string cname = vname.substr(0,found);
// if ( ! support::isDataClass( cname) ) return;
if ( support::isSafeClassName( vname ) ) return;
if ( support::isSafeClassName( t.getAsString() ) ) return;

std::string buf;
llvm::raw_string_ostream os(buf);
Expand Down

0 comments on commit 73b5702

Please sign in to comment.