Skip to content

Commit 7264942

Browse files
author
Kristof Umann
committed
[analyzer][NFC] Fix inconsistent references to checkers as "checks"
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
1 parent 456bfdf commit 7264942

32 files changed

+180
-175
lines changed

clang/include/clang/Analysis/PathDiagnostic.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ using FilesToLineNumsMap = std::map<FileID, std::set<unsigned>>;
725725
/// diagnostic. It represents an ordered-collection of PathDiagnosticPieces,
726726
/// each which represent the pieces of the path.
727727
class PathDiagnostic : public llvm::FoldingSetNode {
728-
std::string CheckName;
728+
std::string CheckerName;
729729
const Decl *DeclWithIssue;
730730
std::string BugType;
731731
std::string VerboseDesc;
@@ -749,7 +749,7 @@ class PathDiagnostic : public llvm::FoldingSetNode {
749749

750750
public:
751751
PathDiagnostic() = delete;
752-
PathDiagnostic(StringRef CheckName, const Decl *DeclWithIssue,
752+
PathDiagnostic(StringRef CheckerName, const Decl *DeclWithIssue,
753753
StringRef bugtype, StringRef verboseDesc, StringRef shortDesc,
754754
StringRef category, PathDiagnosticLocation LocationToUnique,
755755
const Decl *DeclToUnique,
@@ -798,7 +798,7 @@ class PathDiagnostic : public llvm::FoldingSetNode {
798798
return ShortDesc.empty() ? VerboseDesc : ShortDesc;
799799
}
800800

801-
StringRef getCheckName() const { return CheckName; }
801+
StringRef getCheckerName() const { return CheckerName; }
802802
StringRef getBugType() const { return BugType; }
803803
StringRef getCategory() const { return Category; }
804804

clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -163,41 +163,15 @@ class AnalyzerOptions : public RefCountedBase<AnalyzerOptions> {
163163
public:
164164
using ConfigTable = llvm::StringMap<std::string>;
165165

166+
/// Retrieves the list of checkers generated from Checkers.td. This doesn't
167+
/// contain statically linked but non-generated checkers and plugin checkers!
166168
static std::vector<StringRef>
167-
getRegisteredCheckers(bool IncludeExperimental = false) {
168-
static const StringRef StaticAnalyzerChecks[] = {
169-
#define GET_CHECKERS
170-
#define CHECKER(FULLNAME, CLASS, HELPTEXT, DOC_URI, IS_HIDDEN) FULLNAME,
171-
#include "clang/StaticAnalyzer/Checkers/Checkers.inc"
172-
#undef CHECKER
173-
#undef GET_CHECKERS
174-
};
175-
std::vector<StringRef> Checkers;
176-
for (StringRef CheckerName : StaticAnalyzerChecks) {
177-
if (!CheckerName.startswith("debug.") &&
178-
(IncludeExperimental || !CheckerName.startswith("alpha.")))
179-
Checkers.push_back(CheckerName);
180-
}
181-
return Checkers;
182-
}
169+
getRegisteredCheckers(bool IncludeExperimental = false);
183170

171+
/// Retrieves the list of packages generated from Checkers.td. This doesn't
172+
/// contain statically linked but non-generated packages and plugin packages!
184173
static std::vector<StringRef>
185-
getRegisteredPackages(bool IncludeExperimental = false) {
186-
static const StringRef StaticAnalyzerPackages[] = {
187-
#define GET_PACKAGES
188-
#define PACKAGE(FULLNAME) FULLNAME,
189-
#include "clang/StaticAnalyzer/Checkers/Checkers.inc"
190-
#undef PACKAGE
191-
#undef GET_PACKAGES
192-
};
193-
std::vector<StringRef> Packages;
194-
for (StringRef PackageName : StaticAnalyzerPackages) {
195-
if (PackageName != "debug" &&
196-
(IncludeExperimental || PackageName != "alpha"))
197-
Packages.push_back(PackageName);
198-
}
199-
return Packages;
200-
}
174+
getRegisteredPackages(bool IncludeExperimental = false);
201175

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

250-
/// Disable all analyzer checks.
224+
/// Disable all analyzer checkers.
251225
///
252-
/// This flag allows one to disable analyzer checks on the code processed by
226+
/// This flag allows one to disable analyzer checkers on the code processed by
253227
/// the given analysis consumer. Note, the code will get parsed and the
254228
/// command-line options will get checked.
255-
unsigned DisableAllChecks : 1;
229+
unsigned DisableAllCheckers : 1;
256230

257231
unsigned ShowCheckerHelp : 1;
258232
unsigned ShowCheckerHelpAlpha : 1;
@@ -327,7 +301,7 @@ class AnalyzerOptions : public RefCountedBase<AnalyzerOptions> {
327301
}
328302

329303
AnalyzerOptions()
330-
: DisableAllChecks(false), ShowCheckerHelp(false),
304+
: DisableAllCheckers(false), ShowCheckerHelp(false),
331305
ShowCheckerHelpAlpha(false), ShowCheckerHelpDeveloper(false),
332306
ShowCheckerOptionList(false), ShowCheckerOptionAlphaList(false),
333307
ShowCheckerOptionDeveloperList(false), ShowEnabledCheckerList(false),
@@ -345,7 +319,7 @@ class AnalyzerOptions : public RefCountedBase<AnalyzerOptions> {
345319
/// If an option value is not provided, returns the given \p DefaultVal.
346320
/// @param [in] CheckerName The *full name* of the checker. One may retrieve
347321
/// this from the checker object's field \c Name, or through \c
348-
/// CheckerManager::getCurrentCheckName within the checker's registry
322+
/// CheckerManager::getCurrentCheckerName within the checker's registry
349323
/// function.
350324
/// Checker options are retrieved in the following format:
351325
/// `-analyzer-config CheckerName:OptionName=Value.
@@ -365,7 +339,7 @@ class AnalyzerOptions : public RefCountedBase<AnalyzerOptions> {
365339
/// If an option value is not provided, returns the given \p DefaultVal.
366340
/// @param [in] CheckerName The *full name* of the checker. One may retrieve
367341
/// this from the checker object's field \c Name, or through \c
368-
/// CheckerManager::getCurrentCheckName within the checker's registry
342+
/// CheckerManager::getCurrentCheckerName within the checker's registry
369343
/// function.
370344
/// Checker options are retrieved in the following format:
371345
/// `-analyzer-config CheckerName:OptionName=Value.
@@ -385,7 +359,7 @@ class AnalyzerOptions : public RefCountedBase<AnalyzerOptions> {
385359
/// If an option value is not provided, returns the given \p DefaultVal.
386360
/// @param [in] CheckerName The *full name* of the checker. One may retrieve
387361
/// this from the checker object's field \c Name, or through \c
388-
/// CheckerManager::getCurrentCheckName within the checker's registry
362+
/// CheckerManager::getCurrentCheckerName within the checker's registry
389363
/// function.
390364
/// Checker options are retrieved in the following format:
391365
/// `-analyzer-config CheckerName:OptionName=Value.
@@ -439,6 +413,42 @@ inline UserModeKind AnalyzerOptions::getUserMode() const {
439413
return K.getValue();
440414
}
441415

416+
inline std::vector<StringRef>
417+
AnalyzerOptions::getRegisteredCheckers(bool IncludeExperimental) {
418+
static const StringRef StaticAnalyzerCheckerNames[] = {
419+
#define GET_CHECKERS
420+
#define CHECKER(FULLNAME, CLASS, HELPTEXT, DOC_URI, IS_HIDDEN) FULLNAME,
421+
#include "clang/StaticAnalyzer/Checkers/Checkers.inc"
422+
#undef CHECKER
423+
#undef GET_CHECKERS
424+
};
425+
std::vector<StringRef> Checkers;
426+
for (StringRef CheckerName : StaticAnalyzerCheckerNames) {
427+
if (!CheckerName.startswith("debug.") &&
428+
(IncludeExperimental || !CheckerName.startswith("alpha.")))
429+
Checkers.push_back(CheckerName);
430+
}
431+
return Checkers;
432+
}
433+
434+
inline std::vector<StringRef>
435+
AnalyzerOptions::getRegisteredPackages(bool IncludeExperimental) {
436+
static const StringRef StaticAnalyzerPackageNames[] = {
437+
#define GET_PACKAGES
438+
#define PACKAGE(FULLNAME) FULLNAME,
439+
#include "clang/StaticAnalyzer/Checkers/Checkers.inc"
440+
#undef PACKAGE
441+
#undef GET_PACKAGES
442+
};
443+
std::vector<StringRef> Packages;
444+
for (StringRef PackageName : StaticAnalyzerPackageNames) {
445+
if (PackageName != "debug" &&
446+
(IncludeExperimental || PackageName != "alpha"))
447+
Packages.push_back(PackageName);
448+
}
449+
return Packages;
450+
}
451+
442452
} // namespace clang
443453

444454
#endif // LLVM_CLANG_STATICANALYZER_CORE_ANALYZEROPTIONS_H

clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ class BugReporter {
621621
ArrayRef<SourceRange> Ranges = None,
622622
ArrayRef<FixItHint> Fixits = None);
623623

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

633633
/// Returns a BugType that is associated with the given name and
634634
/// category.
635-
BugType *getBugTypeForName(CheckName CheckName, StringRef name,
635+
BugType *getBugTypeForName(CheckerNameRef CheckerName, StringRef name,
636636
StringRef category);
637637

638638
virtual BugReport *

clang/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,36 @@ class ExprEngine;
2828

2929
class BugType {
3030
private:
31-
const CheckName Check;
32-
const std::string Name;
31+
const CheckerNameRef CheckerName;
32+
const std::string Description;
3333
const std::string Category;
3434
const CheckerBase *Checker;
3535
bool SuppressOnSink;
3636

3737
virtual void anchor();
3838

3939
public:
40-
BugType(CheckName Check, StringRef Name, StringRef Cat,
41-
bool SuppressOnSink=false)
42-
: Check(Check), Name(Name), Category(Cat), Checker(nullptr),
43-
SuppressOnSink(SuppressOnSink) {}
40+
BugType(CheckerNameRef CheckerName, StringRef Name, StringRef Cat,
41+
bool SuppressOnSink = false)
42+
: CheckerName(CheckerName), Description(Name), Category(Cat),
43+
Checker(nullptr), SuppressOnSink(SuppressOnSink) {}
4444
BugType(const CheckerBase *Checker, StringRef Name, StringRef Cat,
45-
bool SuppressOnSink=false)
46-
: Check(Checker->getCheckName()), Name(Name), Category(Cat),
47-
Checker(Checker), SuppressOnSink(SuppressOnSink) {}
45+
bool SuppressOnSink = false)
46+
: CheckerName(Checker->getCheckerName()), Description(Name),
47+
Category(Cat), Checker(Checker), SuppressOnSink(SuppressOnSink) {}
4848
virtual ~BugType() = default;
4949

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

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

7777
BuiltinBug(const CheckerBase *checker, const char *name,
7878
const char *description)

clang/include/clang/StaticAnalyzer/Core/Checker.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,12 +490,12 @@ class Call {
490490
} // end eval namespace
491491

492492
class CheckerBase : public ProgramPointTag {
493-
CheckName Name;
493+
CheckerNameRef Name;
494494
friend class ::clang::ento::CheckerManager;
495495

496496
public:
497497
StringRef getTagDescription() const override;
498-
CheckName getCheckName() const;
498+
CheckerNameRef getCheckerName() const;
499499

500500
/// See CheckerManager::runCheckersForPrintState.
501501
virtual void printState(raw_ostream &Out, ProgramStateRef State,

clang/include/clang/StaticAnalyzer/Core/CheckerManager.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,20 @@ enum PointerEscapeKind {
9090
PSK_EscapeOther
9191
};
9292

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

100101
StringRef Name;
101102

102-
explicit CheckName(StringRef Name) : Name(Name) {}
103+
explicit CheckerNameRef(StringRef Name) : Name(Name) {}
103104

104105
public:
105-
CheckName() = default;
106+
CheckerNameRef() = default;
106107

107108
StringRef getName() const { return Name; }
108109
operator StringRef() const { return Name; }
@@ -118,16 +119,16 @@ class CheckerManager {
118119
ASTContext &Context;
119120
const LangOptions LangOpts;
120121
AnalyzerOptions &AOptions;
121-
CheckName CurrentCheckName;
122+
CheckerNameRef CurrentCheckerName;
122123

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

127128
~CheckerManager();
128129

129-
void setCurrentCheckName(CheckName name) { CurrentCheckName = name; }
130-
CheckName getCurrentCheckName() const { return CurrentCheckName; }
130+
void setCurrentCheckerName(CheckerNameRef name) { CurrentCheckerName = name; }
131+
CheckerNameRef getCurrentCheckerName() const { return CurrentCheckerName; }
131132

132133
bool hasPathSensitiveCheckers() const;
133134

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

165166
CHECKER *checker = new CHECKER(std::forward<AT>(Args)...);
166-
checker->Name = CurrentCheckName;
167+
checker->Name = CurrentCheckerName;
167168
CheckerDtors.push_back(CheckerDtor(checker, destruct<CHECKER>));
168169
CHECKER::_register(checker, *this);
169170
ref = checker;

clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ class ExprEngine : public SubEngine {
666666
const LocationContext *LCtx,
667667
ProgramStateRef State);
668668

669-
/// Evaluate a call, running pre- and post-call checks and allowing checkers
669+
/// Evaluate a call, running pre- and post-call checkers and allowing checkers
670670
/// to be responsible for handling the evaluation of the call itself.
671671
void evalCall(ExplodedNodeSet &Dst, ExplodedNode *Pred,
672672
const CallEvent &Call);

clang/lib/Analysis/PathDiagnostic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ void PathPieces::flattenTo(PathPieces &Primary, PathPieces &Current,
117117
PathDiagnostic::~PathDiagnostic() = default;
118118

119119
PathDiagnostic::PathDiagnostic(
120-
StringRef CheckName, const Decl *declWithIssue, StringRef bugtype,
120+
StringRef CheckerName, const Decl *declWithIssue, StringRef bugtype,
121121
StringRef verboseDesc, StringRef shortDesc, StringRef category,
122122
PathDiagnosticLocation LocationToUnique, const Decl *DeclToUnique,
123123
std::unique_ptr<FilesToLineNumsMap> ExecutedLines)
124-
: CheckName(CheckName), DeclWithIssue(declWithIssue),
124+
: CheckerName(CheckerName), DeclWithIssue(declWithIssue),
125125
BugType(StripTrailingDots(bugtype)),
126126
VerboseDesc(StripTrailingDots(verboseDesc)),
127127
ShortDesc(StripTrailingDots(shortDesc)),

clang/lib/Analysis/plugins/SampleAnalyzer/MainCallChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void MainCallChecker::checkPreStmt(const CallExpr *CE,
3737
BT.reset(new BugType(this, "call to main", "example analyzer plugin"));
3838

3939
auto report =
40-
std::make_unique<PathSensitiveBugReport>(*BT, BT->getName(), N);
40+
std::make_unique<PathSensitiveBugReport>(*BT, BT->getDescription(), N);
4141
report->addRange(Callee->getSourceRange());
4242
C.emitReport(std::move(report));
4343
}

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args,
303303
.Case("true", true)
304304
.Case("false", false)
305305
.Default(false);
306-
Opts.DisableAllChecks = Args.hasArg(OPT_analyzer_disable_all_checks);
306+
Opts.DisableAllCheckers = Args.hasArg(OPT_analyzer_disable_all_checks);
307307

308308
Opts.visualizeExplodedGraphWithGraphViz =
309309
Args.hasArg(OPT_analyzer_viz_egraph_graphviz);

0 commit comments

Comments
 (0)