Skip to content

Commit a71c9d8

Browse files
authored
[NFC][analyzer] Remove CheckerNameRef::getName() (#130780)
`CheckerNameRef` is a trivial wrapper around a `StringRef` which is guaranteed to be owned by the `CheckerRegistry` (the only `friend` of the class) because other code can't call the private constructor. This class had offered two ways to recover the plain `StringRef`: an an `operator StringRef()` for implicit conversion and a method `StringRef getName()` which could be called explicitly. However this method name was really confusing, because it implies "get the name of this object" instead of "get this name as a plain `StringRef`"; so I removed it from the codebase and used `static_cast<StringRef>` in the two locations where the cast wasn't performed implicitly. This commit "prepares the ground" for planned improvements in checker name handling.
1 parent c542f42 commit a71c9d8

File tree

7 files changed

+16
-19
lines changed

7 files changed

+16
-19
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ class CheckerNameRef {
113113
public:
114114
CheckerNameRef() = default;
115115

116-
StringRef getName() const { return Name; }
117116
operator StringRef() const { return Name; }
118117
};
119118

clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ void ExprInspectionChecker::analyzerHashDump(const CallExpr *CE,
431431
const SourceManager &SM = C.getSourceManager();
432432
FullSourceLoc FL(CE->getArg(0)->getBeginLoc(), SM);
433433
std::string HashContent =
434-
getIssueString(FL, getCheckerName().getName(), "Category",
434+
getIssueString(FL, getCheckerName(), "Category",
435435
C.getLocationContext()->getDecl(), Opts);
436436

437437
reportBug(HashContent, C);

clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3885,7 +3885,7 @@ void MallocChecker::printState(raw_ostream &Out, ProgramStateRef State,
38853885
Out << " : ";
38863886
Data.dump(Out);
38873887
if (CheckKind)
3888-
Out << " (" << CheckNames[*CheckKind].getName() << ")";
3888+
Out << " (" << CheckNames[*CheckKind] << ")";
38893889
Out << NL;
38903890
}
38913891
}

clang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,12 @@ void ValistChecker::reportLeakedVALists(const RegionVector &LeakedVALists,
272272
if (!BT_leakedvalist) {
273273
// FIXME: maybe creating a new check name for this type of bug is a better
274274
// solution.
275-
BT_leakedvalist.reset(
276-
new BugType(CheckNames[CK_Unterminated].getName().empty()
277-
? CheckNames[CK_Uninitialized]
278-
: CheckNames[CK_Unterminated],
279-
"Leaked va_list", categories::MemoryError,
280-
/*SuppressOnSink=*/true));
275+
BT_leakedvalist.reset(new BugType(
276+
static_cast<StringRef>(CheckNames[CK_Unterminated]).empty()
277+
? CheckNames[CK_Uninitialized]
278+
: CheckNames[CK_Unterminated],
279+
"Leaked va_list", categories::MemoryError,
280+
/*SuppressOnSink=*/true));
281281
}
282282

283283
const ExplodedNode *StartNode = getStartCallSite(N, Reg);

clang/lib/StaticAnalyzer/Core/BugReporter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3442,8 +3442,8 @@ void BugReporter::EmitBasicReport(const Decl *DeclWithIssue,
34423442
BugType *BugReporter::getBugTypeForName(CheckerNameRef CheckName,
34433443
StringRef name, StringRef category) {
34443444
SmallString<136> fullDesc;
3445-
llvm::raw_svector_ostream(fullDesc) << CheckName.getName() << ":" << name
3446-
<< ":" << category;
3445+
llvm::raw_svector_ostream(fullDesc)
3446+
<< CheckName << ":" << name << ":" << category;
34473447
std::unique_ptr<BugType> &BT = StrBugTypes[fullDesc];
34483448
if (!BT)
34493449
BT = std::make_unique<BugType>(CheckName, name, category);

clang/lib/StaticAnalyzer/Core/Checker.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ using namespace ento;
1818

1919
int ImplicitNullDerefEvent::Tag;
2020

21-
StringRef CheckerBase::getTagDescription() const {
22-
return getCheckerName().getName();
23-
}
21+
StringRef CheckerBase::getTagDescription() const { return getCheckerName(); }
2422

2523
CheckerNameRef CheckerBase::getCheckerName() const { return Name; }
2624

@@ -30,10 +28,10 @@ CheckerProgramPointTag::CheckerProgramPointTag(StringRef CheckerName,
3028

3129
CheckerProgramPointTag::CheckerProgramPointTag(const CheckerBase *Checker,
3230
StringRef Msg)
33-
: SimpleProgramPointTag(Checker->getCheckerName().getName(), Msg) {}
31+
: SimpleProgramPointTag(Checker->getCheckerName(), Msg) {}
3432

3533
raw_ostream& clang::ento::operator<<(raw_ostream &Out,
3634
const CheckerBase &Checker) {
37-
Out << Checker.getCheckerName().getName();
35+
Out << Checker.getCheckerName();
3836
return Out;
3937
}

clang/lib/StaticAnalyzer/Core/CheckerManager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ std::string checkerScopeName(StringRef Name, const CheckerBase *Checker) {
139139
if (!llvm::timeTraceProfilerEnabled())
140140
return "";
141141
StringRef CheckerName =
142-
Checker ? Checker->getCheckerName().getName() : "<unknown>";
142+
Checker ? static_cast<StringRef>(Checker->getCheckerName()) : "<unknown>";
143143
return (Name + ":" + CheckerName).str();
144144
}
145145

@@ -721,7 +721,7 @@ void CheckerManager::runCheckersForEvalCall(ExplodedNodeSet &Dst,
721721
"The '{0}' call has been already evaluated by the {1} checker, "
722722
"while the {2} checker also tried to evaluate the same call. At "
723723
"most one checker supposed to evaluate a call.",
724-
toString(Call), evaluatorChecker->getName(),
724+
toString(Call), evaluatorChecker,
725725
EvalCallChecker.Checker->getCheckerName());
726726
llvm_unreachable(AssertionMessage.c_str());
727727
}
@@ -799,7 +799,7 @@ void CheckerManager::runCheckersForPrintStateJson(raw_ostream &Out,
799799
continue;
800800

801801
Indent(Out, Space, IsDot)
802-
<< "{ \"checker\": \"" << CT.second->getCheckerName().getName()
802+
<< "{ \"checker\": \"" << CT.second->getCheckerName()
803803
<< "\", \"messages\": [" << NL;
804804
Indent(Out, InnerSpace, IsDot)
805805
<< '\"' << TempBuf.str().trim() << '\"' << NL;

0 commit comments

Comments
 (0)