Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions Utilities/StaticAnalyzers/src/ConstCastAwayChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,10 @@ namespace clangcms {
os << "const qualifier was removed via a cast, this may result in thread-unsafe code.";
std::unique_ptr<clang::ento::PathSensitiveBugReport> PSBR =
std::make_unique<clang::ento::PathSensitiveBugReport>(*BT, llvm::StringRef(os.str()), errorNode);
std::unique_ptr<clang::ento::BasicBugReport> R =
std::make_unique<clang::ento::BasicBugReport>(*BT, llvm::StringRef(os.str()), PSBR->getLocation());
R->addRange(CE->getSourceRange());
if (!m_exception.reportConstCastAway(*R, C))
PSBR->addRange(CE->getSourceRange());
if (!m_exception.reportConstCastAway(*PSBR, C))
return;
C.emitReport(std::move(R));
C.emitReport(std::move(PSBR));
if (cname.empty())
return;
std::string tname = "constcastaway-checker.txt.unsorted";
Expand Down
8 changes: 3 additions & 5 deletions Utilities/StaticAnalyzers/src/ConstCastChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,10 @@ namespace clangcms {
os << "const_cast was used, this may result in thread-unsafe code.";
std::unique_ptr<clang::ento::PathSensitiveBugReport> PSBR =
std::make_unique<clang::ento::PathSensitiveBugReport>(*BT, llvm::StringRef(os.str()), errorNode);
std::unique_ptr<clang::ento::BasicBugReport> R =
std::make_unique<clang::ento::BasicBugReport>(*BT, llvm::StringRef(os.str()), PSBR->getLocation());
R->addRange(CE->getSourceRange());
if (!m_exception.reportConstCast(*R, C))
PSBR->addRange(CE->getSourceRange());
if (!m_exception.reportConstCast(*PSBR, C))
return;
C.emitReport(std::move(R));
C.emitReport(std::move(PSBR));
if (cname.empty())
return;
std::string tname = "constcast-checker.txt.unsorted";
Expand Down
27 changes: 22 additions & 5 deletions Utilities/StaticAnalyzers/src/FunctionChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ namespace clangcms {
std::string buf;
llvm::raw_string_ostream os(buf);
os << "function '" << dname << "' accesses or modifies non-const static local variable '" << svname << "'.\n";
// BR.EmitBasicReport(D, Checker, "non-const static local variable accessed or modified","ThreadSafety",os.str(), DLoc);
BR.EmitBasicReport(D,
Checker->getCheckerName(),
"non-const static local variable accessed or modified",
"ThreadSafety",
os.str(),
DLoc);
std::string ostring = "function '" + sdname + "' static variable '" + vname + "'.\n";
support::writeLog(ostring, tname);
return;
Expand All @@ -115,7 +120,12 @@ namespace clangcms {
llvm::raw_string_ostream os(buf);
os << "function '" << dname << "' accesses or modifies non-const static member data variable '" << svname
<< "'.\n";
// BR.EmitBasicReport(D, Checker, "non-const static local variable accessed or modified","ThreadSafety",os.str(), DLoc);
BR.EmitBasicReport(D,
Checker->getCheckerName(),
"non-const static local variable accessed or modified",
"ThreadSafety",
os.str(),
DLoc);
std::string ostring = "function '" + sdname + "' static variable '" + vname + "'.\n";
support::writeLog(ostring, tname);
return;
Expand All @@ -125,7 +135,12 @@ namespace clangcms {
std::string buf;
llvm::raw_string_ostream os(buf);
os << "function '" << dname << "' accesses or modifies non-const global static variable '" << svname << "'.\n";
// BR.EmitBasicReport(D, Checker, "non-const static local variable accessed or modified","ThreadSafety",os.str(), DLoc);
BR.EmitBasicReport(D,
Checker->getCheckerName(),
"non-const static local variable accessed or modified",
"ThreadSafety",
os.str(),
DLoc);
std::string ostring = "function '" + sdname + "' static variable '" + vname + "'.\n";
support::writeLog(ostring, tname);
return;
Expand Down Expand Up @@ -159,8 +174,10 @@ namespace clangcms {
os << "function '" << dname
<< "' is in an extern \"C\" context and most likely accesses or modifies fortran variables in a "
"'COMMONBLOCK'.\n";
clang::ento::PathDiagnosticLocation::createBegin(FD, BR.getSourceManager());
// BR.EmitBasicReport(FD, "COMMONBLOCK variable accessed or modified","ThreadSafety",os.str(), FDLoc);
clang::ento::PathDiagnosticLocation FDLoc =
clang::ento::PathDiagnosticLocation::createBegin(FD, BR.getSourceManager());
BR.EmitBasicReport(
FD, this->getCheckerName(), "COMMONBLOCK variable accessed or modified", "ThreadSafety", os.str(), FDLoc);
std::string ostring = "function '" + dname + "' static variable 'COMMONBLOCK'.\n";
std::string tname = "function-checker.txt.unsorted";
support::writeLog(ostring, tname);
Expand Down
12 changes: 9 additions & 3 deletions Utilities/StaticAnalyzers/src/GlobalStaticChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ namespace clangcms {

std::string buf;
llvm::raw_string_ostream os(buf);
os << "Non-const variable '" << t.getAsString() << " " << *D << "' is static and might be thread-unsafe";

BR.EmitBasicReport(D, this, "non-const global static variable", "ThreadSafety", os.str(), DLoc);
os << "Non-const variable '" << t.getAsString() << " " << D->getQualifiedNameAsString()
<< "' is static and might be thread-unsafe";
if (!BT)
BT = std::make_unique<clang::ento::BugType>(this, "non-const global static variable", "ThreadSafety");
std::unique_ptr<clang::ento::BasicBugReport> R =
std::make_unique<clang::ento::BasicBugReport>(*BT, llvm::StringRef(os.str()), DLoc);
R->setDeclWithIssue(D);
R->addRange(D->getSourceRange());
BR.emitReport(std::move(R));
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Utilities/StaticAnalyzers/src/GlobalStaticChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace clangcms {
class GlobalStaticChecker : public clang::ento::Checker<clang::ento::check::ASTDecl<clang::VarDecl> > {
CMS_SA_ALLOW mutable std::unique_ptr<clang::ento::BuiltinBug> BT;
CMS_SA_ALLOW mutable std::unique_ptr<clang::ento::BugType> BT;

public:
void checkASTDecl(const clang::VarDecl *D, clang::ento::AnalysisManager &Mgr, clang::ento::BugReporter &BR) const;
Expand Down
16 changes: 11 additions & 5 deletions Utilities/StaticAnalyzers/src/MutableMemberChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ namespace clangcms {
return;
if (D->isMutable() && D->getDeclContext()->isRecord()) {
clang::QualType t = D->getType();
clang::ento::PathDiagnosticLocation DLoc =
clang::ento::PathDiagnosticLocation::createBegin(D, BR.getSourceManager());
clang::ento::PathDiagnosticLocation DLoc = clang::ento::PathDiagnosticLocation::create(D, BR.getSourceManager());

if (!m_exception.reportMutableMember(t, DLoc, BR))
return;
Expand All @@ -29,11 +28,18 @@ namespace clangcms {
std::string buf;
llvm::raw_string_ostream os(buf);
std::string pname = D->getParent()->getQualifiedNameAsString();
os << "Mutable member '" << *D << "' in class '" << pname
os << "Mutable member '" << D->getQualifiedNameAsString() << "' in class '" << pname
<< "', might be thread-unsafe when accessing via a const pointer.";
BR.EmitBasicReport(D, this, "mutable member if accessed via const pointer", "ConstThreadSafety", os.str(), DLoc);
if (!BT)
BT = std::make_unique<clang::ento::BugType>(
this, "mutable member if accessed via const pointer", "ConstThreadSafety");
std::unique_ptr<clang::ento::BasicBugReport> R =
std::make_unique<clang::ento::BasicBugReport>(*BT, llvm::StringRef(os.str()), DLoc);
R->setDeclWithIssue(D);
R->addRange(D->getSourceRange());
BR.emitReport(std::move(R));
std::string tname = "mutablemember-checker.txt.unsorted";
std::string ostring = "flagged class '" + pname + "' mutable member '" + D->getQualifiedNameAsString();
std::string ostring = "flagged class '" + pname + "' mutable member '" + D->getQualifiedNameAsString() + "'";
support::writeLog(ostring, tname);
}
}
Expand Down
3 changes: 1 addition & 2 deletions Utilities/StaticAnalyzers/src/MutableMemberChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@

namespace clangcms {
class MutableMemberChecker : public clang::ento::Checker<clang::ento::check::ASTDecl<clang::FieldDecl> > {
CMS_SA_ALLOW mutable std::unique_ptr<clang::ento::BuiltinBug> BT;

public:
CMS_SA_ALLOW mutable std::unique_ptr<clang::ento::BugType> BT;
void checkASTDecl(const clang::FieldDecl *D, clang::ento::AnalysisManager &Mgr, clang::ento::BugReporter &BR) const;

private:
Expand Down
11 changes: 8 additions & 3 deletions Utilities/StaticAnalyzers/src/StaticLocalChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,15 @@ namespace clangcms {

std::string buf;
llvm::raw_string_ostream os(buf);
os << "Non-const variable '" << t.getAsString() << " " << *D
os << "Non-const variable '" << t.getAsString() << " " << D->getQualifiedNameAsString()
<< "' is static local or static member data and might be thread-unsafe";

BR.EmitBasicReport(D, this, "non-const static variable", "ThreadSafety", os.str(), DLoc);
if (!BT)
BT = std::make_unique<clang::ento::BugType>(this, "non-const static variable", "ThreadSafety");
std::unique_ptr<clang::ento::BasicBugReport> R =
std::make_unique<clang::ento::BasicBugReport>(*BT, llvm::StringRef(os.str()), DLoc);
R->setDeclWithIssue(D);
R->addRange(D->getSourceRange());
BR.emitReport(std::move(R));
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Utilities/StaticAnalyzers/src/StaticLocalChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace clangcms {
class StaticLocalChecker : public clang::ento::Checker<clang::ento::check::ASTDecl<clang::VarDecl> > {
CMS_SA_ALLOW mutable std::unique_ptr<clang::ento::BuiltinBug> BT;
CMS_SA_ALLOW mutable std::unique_ptr<clang::ento::BugType> BT;

public:
void checkASTDecl(const clang::VarDecl *D, clang::ento::AnalysisManager &Mgr, clang::ento::BugReporter &BR) const;
Expand Down