Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flag function declarations in extern "C" blocks ending with _ #1687

Merged
merged 1 commit into from Dec 6, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 16 additions & 3 deletions Utilities/StaticAnalyzers/src/FunctionChecker.cpp
Expand Up @@ -132,29 +132,42 @@ void FunctionChecker::checkASTDecl(const CXXMethodDecl *MD, AnalysisManager& mgr
if (!support::isCmsLocalFile(sfile)) return;
std::string fname(sfile);
if ( fname.find("/test/") != std::string::npos) return;

if (!MD->doesThisDeclarationHaveABody()) return;
FWalker walker(BR, mgr.getAnalysisDeclContext(MD));
walker.Visit(MD->getBody());
return;
}

void FunctionChecker::checkASTDecl(const FunctionDecl *FD, AnalysisManager& mgr,
BugReporter &BR) const {

if (FD-> isInExternCContext()) {
std::string buf;
std::string dname = FD->getQualifiedNameAsString();
if ( dname.compare(dname.size()-1,1,"_") != 0 ) return;
llvm::raw_string_ostream os(buf);
os << "function '"<< dname << "' is in an extern \"C\" context and most likely accesses or modifies fortran variables in a 'COMMONBLOCK'.\n";
clang::ento::PathDiagnosticLocation FDLoc = clang::ento::PathDiagnosticLocation::createBegin(FD, BR.getSourceManager());
BR.EmitBasicReport(FD, "FunctionChecker : COMMONBLOCK variable accessed or modified","ThreadSafety",os.str(), FDLoc);
llvm::errs() << "function '"<<dname << "' static variable 'COMMONBLOCK'.\n\n";
}
}

void FunctionChecker::checkASTDecl(const FunctionTemplateDecl *TD, AnalysisManager& mgr,
BugReporter &BR) const {

const char *sfile=BR.getSourceManager().getPresumedLoc(TD->getLocation ()).getFilename();
if (!support::isCmsLocalFile(sfile)) return;
std::string fname(sfile);
if ( fname.find("/test/") != std::string::npos) return;

for (FunctionTemplateDecl::spec_iterator I = const_cast<clang::FunctionTemplateDecl *>(TD)->spec_begin(),
E = const_cast<clang::FunctionTemplateDecl *>(TD)->spec_end(); I != E; ++I)
{
if (I->doesThisDeclarationHaveABody()) {
FWalker walker(BR, mgr.getAnalysisDeclContext(*I));
walker.Visit(I->getBody());
}
}
}
return;
}

Expand Down
4 changes: 3 additions & 1 deletion Utilities/StaticAnalyzers/src/FunctionChecker.h
Expand Up @@ -10,6 +10,7 @@
namespace clangcms {

class FunctionChecker : public clang::ento::Checker< clang::ento::check::ASTDecl<clang::CXXMethodDecl>,
clang::ento::check::ASTDecl<clang::FunctionDecl>,
clang::ento::check::ASTDecl<clang::FunctionTemplateDecl> >
{
mutable clang::OwningPtr< clang::ento::BugType> BT;
Expand All @@ -19,7 +20,8 @@ class FunctionChecker : public clang::ento::Checker< clang::ento::check::ASTDecl

void checkASTDecl(const clang::CXXMethodDecl *CMD, clang::ento::AnalysisManager& mgr,
clang::ento::BugReporter &BR) const ;

void checkASTDecl(const clang::FunctionDecl *FD, clang::ento::AnalysisManager& mgr,
clang::ento::BugReporter &BR) const ;
void checkASTDecl(const clang::FunctionTemplateDecl *TD, clang::ento::AnalysisManager& mgr,
clang::ento::BugReporter &BR) const ;

Expand Down