Skip to content

Commit

Permalink
[analyzer][NFC] Fix inconsistent references to checkers as "checks"
Browse files Browse the repository at this point in the history
Traditionally, clang-tidy uses the term check, and the analyzer uses checker,
but in the very early years, this wasn't the case, and code originating from the
early 2010's still incorrectly refer to checkers as checks.

This patch attempts to hunt down most of these, aiming to refer to checkers as
checkers, but preserve references to callback functions (like checkPreCall) as
checks.

Differential Revision: https://reviews.llvm.org/D67140

llvm-svn: 371760
  • Loading branch information
Kristof Umann committed Sep 12, 2019
1 parent 456bfdf commit 7264942
Show file tree
Hide file tree
Showing 32 changed files with 180 additions and 175 deletions.
6 changes: 3 additions & 3 deletions clang/include/clang/Analysis/PathDiagnostic.h
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ using FilesToLineNumsMap = std::map<FileID, std::set<unsigned>>;
/// diagnostic. It represents an ordered-collection of PathDiagnosticPieces,
/// each which represent the pieces of the path.
class PathDiagnostic : public llvm::FoldingSetNode {
std::string CheckName;
std::string CheckerName;
const Decl *DeclWithIssue;
std::string BugType;
std::string VerboseDesc;
Expand All @@ -749,7 +749,7 @@ class PathDiagnostic : public llvm::FoldingSetNode {

public:
PathDiagnostic() = delete;
PathDiagnostic(StringRef CheckName, const Decl *DeclWithIssue,
PathDiagnostic(StringRef CheckerName, const Decl *DeclWithIssue,
StringRef bugtype, StringRef verboseDesc, StringRef shortDesc,
StringRef category, PathDiagnosticLocation LocationToUnique,
const Decl *DeclToUnique,
Expand Down Expand Up @@ -798,7 +798,7 @@ class PathDiagnostic : public llvm::FoldingSetNode {
return ShortDesc.empty() ? VerboseDesc : ShortDesc;
}

StringRef getCheckName() const { return CheckName; }
StringRef getCheckerName() const { return CheckerName; }
StringRef getBugType() const { return BugType; }
StringRef getCategory() const { return Category; }

Expand Down
88 changes: 49 additions & 39 deletions clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,41 +163,15 @@ class AnalyzerOptions : public RefCountedBase<AnalyzerOptions> {
public:
using ConfigTable = llvm::StringMap<std::string>;

/// Retrieves the list of checkers generated from Checkers.td. This doesn't
/// contain statically linked but non-generated checkers and plugin checkers!
static std::vector<StringRef>
getRegisteredCheckers(bool IncludeExperimental = false) {
static const StringRef StaticAnalyzerChecks[] = {
#define GET_CHECKERS
#define CHECKER(FULLNAME, CLASS, HELPTEXT, DOC_URI, IS_HIDDEN) FULLNAME,
#include "clang/StaticAnalyzer/Checkers/Checkers.inc"
#undef CHECKER
#undef GET_CHECKERS
};
std::vector<StringRef> Checkers;
for (StringRef CheckerName : StaticAnalyzerChecks) {
if (!CheckerName.startswith("debug.") &&
(IncludeExperimental || !CheckerName.startswith("alpha.")))
Checkers.push_back(CheckerName);
}
return Checkers;
}
getRegisteredCheckers(bool IncludeExperimental = false);

/// Retrieves the list of packages generated from Checkers.td. This doesn't
/// contain statically linked but non-generated packages and plugin packages!
static std::vector<StringRef>
getRegisteredPackages(bool IncludeExperimental = false) {
static const StringRef StaticAnalyzerPackages[] = {
#define GET_PACKAGES
#define PACKAGE(FULLNAME) FULLNAME,
#include "clang/StaticAnalyzer/Checkers/Checkers.inc"
#undef PACKAGE
#undef GET_PACKAGES
};
std::vector<StringRef> Packages;
for (StringRef PackageName : StaticAnalyzerPackages) {
if (PackageName != "debug" &&
(IncludeExperimental || PackageName != "alpha"))
Packages.push_back(PackageName);
}
return Packages;
}
getRegisteredPackages(bool IncludeExperimental = false);

/// Convenience function for printing options or checkers and their
/// description in a formatted manner. If \p MinLineWidth is set to 0, no line
Expand Down Expand Up @@ -247,12 +221,12 @@ class AnalyzerOptions : public RefCountedBase<AnalyzerOptions> {
/// The maximum number of times the analyzer visits a block.
unsigned maxBlockVisitOnPath;

/// Disable all analyzer checks.
/// Disable all analyzer checkers.
///
/// This flag allows one to disable analyzer checks on the code processed by
/// This flag allows one to disable analyzer checkers on the code processed by
/// the given analysis consumer. Note, the code will get parsed and the
/// command-line options will get checked.
unsigned DisableAllChecks : 1;
unsigned DisableAllCheckers : 1;

unsigned ShowCheckerHelp : 1;
unsigned ShowCheckerHelpAlpha : 1;
Expand Down Expand Up @@ -327,7 +301,7 @@ class AnalyzerOptions : public RefCountedBase<AnalyzerOptions> {
}

AnalyzerOptions()
: DisableAllChecks(false), ShowCheckerHelp(false),
: DisableAllCheckers(false), ShowCheckerHelp(false),
ShowCheckerHelpAlpha(false), ShowCheckerHelpDeveloper(false),
ShowCheckerOptionList(false), ShowCheckerOptionAlphaList(false),
ShowCheckerOptionDeveloperList(false), ShowEnabledCheckerList(false),
Expand All @@ -345,7 +319,7 @@ class AnalyzerOptions : public RefCountedBase<AnalyzerOptions> {
/// If an option value is not provided, returns the given \p DefaultVal.
/// @param [in] CheckerName The *full name* of the checker. One may retrieve
/// this from the checker object's field \c Name, or through \c
/// CheckerManager::getCurrentCheckName within the checker's registry
/// CheckerManager::getCurrentCheckerName within the checker's registry
/// function.
/// Checker options are retrieved in the following format:
/// `-analyzer-config CheckerName:OptionName=Value.
Expand All @@ -365,7 +339,7 @@ class AnalyzerOptions : public RefCountedBase<AnalyzerOptions> {
/// If an option value is not provided, returns the given \p DefaultVal.
/// @param [in] CheckerName The *full name* of the checker. One may retrieve
/// this from the checker object's field \c Name, or through \c
/// CheckerManager::getCurrentCheckName within the checker's registry
/// CheckerManager::getCurrentCheckerName within the checker's registry
/// function.
/// Checker options are retrieved in the following format:
/// `-analyzer-config CheckerName:OptionName=Value.
Expand All @@ -385,7 +359,7 @@ class AnalyzerOptions : public RefCountedBase<AnalyzerOptions> {
/// If an option value is not provided, returns the given \p DefaultVal.
/// @param [in] CheckerName The *full name* of the checker. One may retrieve
/// this from the checker object's field \c Name, or through \c
/// CheckerManager::getCurrentCheckName within the checker's registry
/// CheckerManager::getCurrentCheckerName within the checker's registry
/// function.
/// Checker options are retrieved in the following format:
/// `-analyzer-config CheckerName:OptionName=Value.
Expand Down Expand Up @@ -439,6 +413,42 @@ inline UserModeKind AnalyzerOptions::getUserMode() const {
return K.getValue();
}

inline std::vector<StringRef>
AnalyzerOptions::getRegisteredCheckers(bool IncludeExperimental) {
static const StringRef StaticAnalyzerCheckerNames[] = {
#define GET_CHECKERS
#define CHECKER(FULLNAME, CLASS, HELPTEXT, DOC_URI, IS_HIDDEN) FULLNAME,
#include "clang/StaticAnalyzer/Checkers/Checkers.inc"
#undef CHECKER
#undef GET_CHECKERS
};
std::vector<StringRef> Checkers;
for (StringRef CheckerName : StaticAnalyzerCheckerNames) {
if (!CheckerName.startswith("debug.") &&
(IncludeExperimental || !CheckerName.startswith("alpha.")))
Checkers.push_back(CheckerName);
}
return Checkers;
}

inline std::vector<StringRef>
AnalyzerOptions::getRegisteredPackages(bool IncludeExperimental) {
static const StringRef StaticAnalyzerPackageNames[] = {
#define GET_PACKAGES
#define PACKAGE(FULLNAME) FULLNAME,
#include "clang/StaticAnalyzer/Checkers/Checkers.inc"
#undef PACKAGE
#undef GET_PACKAGES
};
std::vector<StringRef> Packages;
for (StringRef PackageName : StaticAnalyzerPackageNames) {
if (PackageName != "debug" &&
(IncludeExperimental || PackageName != "alpha"))
Packages.push_back(PackageName);
}
return Packages;
}

} // namespace clang

#endif // LLVM_CLANG_STATICANALYZER_CORE_ANALYZEROPTIONS_H
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ class BugReporter {
ArrayRef<SourceRange> Ranges = None,
ArrayRef<FixItHint> Fixits = None);

void EmitBasicReport(const Decl *DeclWithIssue, CheckName CheckName,
void EmitBasicReport(const Decl *DeclWithIssue, CheckerNameRef CheckerName,
StringRef BugName, StringRef BugCategory,
StringRef BugStr, PathDiagnosticLocation Loc,
ArrayRef<SourceRange> Ranges = None,
Expand All @@ -632,7 +632,7 @@ class BugReporter {

/// Returns a BugType that is associated with the given name and
/// category.
BugType *getBugTypeForName(CheckName CheckName, StringRef name,
BugType *getBugTypeForName(CheckerNameRef CheckerName, StringRef name,
StringRef category);

virtual BugReport *
Expand Down
40 changes: 20 additions & 20 deletions clang/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,36 @@ class ExprEngine;

class BugType {
private:
const CheckName Check;
const std::string Name;
const CheckerNameRef CheckerName;
const std::string Description;
const std::string Category;
const CheckerBase *Checker;
bool SuppressOnSink;

virtual void anchor();

public:
BugType(CheckName Check, StringRef Name, StringRef Cat,
bool SuppressOnSink=false)
: Check(Check), Name(Name), Category(Cat), Checker(nullptr),
SuppressOnSink(SuppressOnSink) {}
BugType(CheckerNameRef CheckerName, StringRef Name, StringRef Cat,
bool SuppressOnSink = false)
: CheckerName(CheckerName), Description(Name), Category(Cat),
Checker(nullptr), SuppressOnSink(SuppressOnSink) {}
BugType(const CheckerBase *Checker, StringRef Name, StringRef Cat,
bool SuppressOnSink=false)
: Check(Checker->getCheckName()), Name(Name), Category(Cat),
Checker(Checker), SuppressOnSink(SuppressOnSink) {}
bool SuppressOnSink = false)
: CheckerName(Checker->getCheckerName()), Description(Name),
Category(Cat), Checker(Checker), SuppressOnSink(SuppressOnSink) {}
virtual ~BugType() = default;

StringRef getName() const { return Name; }
StringRef getDescription() const { return Description; }
StringRef getCategory() const { return Category; }
StringRef getCheckName() const {
// FIXME: This is a workaround to ensure that the correct check name is used
// The check names are set after the constructors are run.
StringRef getCheckerName() const {
// FIXME: This is a workaround to ensure that the correct checerk name is
// used. The checker names are set after the constructors are run.
// In case the BugType object is initialized in the checker's ctor
// the Check field will be empty. To circumvent this problem we use
// the CheckerName field will be empty. To circumvent this problem we use
// CheckerBase whenever it is possible.
StringRef CheckName =
Checker ? Checker->getCheckName().getName() : Check.getName();
assert(!CheckName.empty() && "Check name is not set properly.");
return CheckName;
StringRef Ret = Checker ? Checker->getCheckerName() : CheckerName;
assert(!Ret.empty() && "Checker name is not set properly.");
return Ret;
}

/// isSuppressOnSink - Returns true if bug reports associated with this bug
Expand All @@ -71,8 +70,9 @@ class BuiltinBug : public BugType {
const std::string desc;
void anchor() override;
public:
BuiltinBug(class CheckName check, const char *name, const char *description)
: BugType(check, name, categories::LogicError), desc(description) {}
BuiltinBug(class CheckerNameRef checker, const char *name,
const char *description)
: BugType(checker, name, categories::LogicError), desc(description) {}

BuiltinBug(const CheckerBase *checker, const char *name,
const char *description)
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/StaticAnalyzer/Core/Checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,12 +490,12 @@ class Call {
} // end eval namespace

class CheckerBase : public ProgramPointTag {
CheckName Name;
CheckerNameRef Name;
friend class ::clang::ento::CheckerManager;

public:
StringRef getTagDescription() const override;
CheckName getCheckName() const;
CheckerNameRef getCheckerName() const;

/// See CheckerManager::runCheckersForPrintState.
virtual void printState(raw_ostream &Out, ProgramStateRef State,
Expand Down
23 changes: 12 additions & 11 deletions clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,20 @@ enum PointerEscapeKind {
PSK_EscapeOther
};

// This wrapper is used to ensure that only StringRefs originating from the
// CheckerRegistry are used as check names. We want to make sure all check
// name strings have a lifetime that keeps them alive at least until the path
// diagnostics have been processed.
class CheckName {
/// This wrapper is used to ensure that only StringRefs originating from the
/// CheckerRegistry are used as check names. We want to make sure all checker
/// name strings have a lifetime that keeps them alive at least until the path
/// diagnostics have been processed, since they are expected to be constexpr
/// string literals (most likely generated by TblGen).
class CheckerNameRef {
friend class ::clang::ento::CheckerRegistry;

StringRef Name;

explicit CheckName(StringRef Name) : Name(Name) {}
explicit CheckerNameRef(StringRef Name) : Name(Name) {}

public:
CheckName() = default;
CheckerNameRef() = default;

StringRef getName() const { return Name; }
operator StringRef() const { return Name; }
Expand All @@ -118,16 +119,16 @@ class CheckerManager {
ASTContext &Context;
const LangOptions LangOpts;
AnalyzerOptions &AOptions;
CheckName CurrentCheckName;
CheckerNameRef CurrentCheckerName;

public:
CheckerManager(ASTContext &Context, AnalyzerOptions &AOptions)
: Context(Context), LangOpts(Context.getLangOpts()), AOptions(AOptions) {}

~CheckerManager();

void setCurrentCheckName(CheckName name) { CurrentCheckName = name; }
CheckName getCurrentCheckName() const { return CurrentCheckName; }
void setCurrentCheckerName(CheckerNameRef name) { CurrentCheckerName = name; }
CheckerNameRef getCurrentCheckerName() const { return CurrentCheckerName; }

bool hasPathSensitiveCheckers() const;

Expand Down Expand Up @@ -163,7 +164,7 @@ class CheckerManager {
assert(!ref && "Checker already registered, use getChecker!");

CHECKER *checker = new CHECKER(std::forward<AT>(Args)...);
checker->Name = CurrentCheckName;
checker->Name = CurrentCheckerName;
CheckerDtors.push_back(CheckerDtor(checker, destruct<CHECKER>));
CHECKER::_register(checker, *this);
ref = checker;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ class ExprEngine : public SubEngine {
const LocationContext *LCtx,
ProgramStateRef State);

/// Evaluate a call, running pre- and post-call checks and allowing checkers
/// Evaluate a call, running pre- and post-call checkers and allowing checkers
/// to be responsible for handling the evaluation of the call itself.
void evalCall(ExplodedNodeSet &Dst, ExplodedNode *Pred,
const CallEvent &Call);
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Analysis/PathDiagnostic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ void PathPieces::flattenTo(PathPieces &Primary, PathPieces &Current,
PathDiagnostic::~PathDiagnostic() = default;

PathDiagnostic::PathDiagnostic(
StringRef CheckName, const Decl *declWithIssue, StringRef bugtype,
StringRef CheckerName, const Decl *declWithIssue, StringRef bugtype,
StringRef verboseDesc, StringRef shortDesc, StringRef category,
PathDiagnosticLocation LocationToUnique, const Decl *DeclToUnique,
std::unique_ptr<FilesToLineNumsMap> ExecutedLines)
: CheckName(CheckName), DeclWithIssue(declWithIssue),
: CheckerName(CheckerName), DeclWithIssue(declWithIssue),
BugType(StripTrailingDots(bugtype)),
VerboseDesc(StripTrailingDots(verboseDesc)),
ShortDesc(StripTrailingDots(shortDesc)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void MainCallChecker::checkPreStmt(const CallExpr *CE,
BT.reset(new BugType(this, "call to main", "example analyzer plugin"));

auto report =
std::make_unique<PathSensitiveBugReport>(*BT, BT->getName(), N);
std::make_unique<PathSensitiveBugReport>(*BT, BT->getDescription(), N);
report->addRange(Callee->getSourceRange());
C.emitReport(std::move(report));
}
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args,
.Case("true", true)
.Case("false", false)
.Default(false);
Opts.DisableAllChecks = Args.hasArg(OPT_analyzer_disable_all_checks);
Opts.DisableAllCheckers = Args.hasArg(OPT_analyzer_disable_all_checks);

Opts.visualizeExplodedGraphWithGraphViz =
Args.hasArg(OPT_analyzer_viz_egraph_graphviz);
Expand Down
Loading

0 comments on commit 7264942

Please sign in to comment.