[clang] 1970145 - [clang][nearly-NFC] Remove some superfluous uses of NamedDecl::getNameAsString
Bruno Ricci via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 5 05:55:42 PDT 2020
Author: Bruno Ricci
Date: 2020-08-05T13:54:37+01:00
New Revision: 19701458d4691ee7ec59e5aa7217a479b0fb10e7
URL: https://github.com/llvm/llvm-project/commit/19701458d4691ee7ec59e5aa7217a479b0fb10e7
DIFF: https://github.com/llvm/llvm-project/commit/19701458d4691ee7ec59e5aa7217a479b0fb10e7.diff
LOG: [clang][nearly-NFC] Remove some superfluous uses of NamedDecl::getNameAsString
`OS << ND->getDeclName();` is equivalent to `OS << ND->getNameAsString();`
without the extra temporary string.
This is not quite a NFC since two uses of `getNameAsString` in a
diagnostic are replaced, which results in the named entity being
quoted with additional "'"s (ie: 'var' instead of var).
Added:
Modified:
clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllSymbols.cpp
clang-tools-extra/clang-move/HelperDeclRefGraph.cpp
clang-tools-extra/clang-move/Move.cpp
clang/lib/AST/ASTDiagnostic.cpp
clang/lib/AST/Interp/Disasm.cpp
clang/lib/AST/TextNodeDumper.cpp
clang/lib/Frontend/FrontendAction.cpp
clang/lib/Index/FileIndexRecord.cpp
clang/lib/Sema/AnalysisBasedWarnings.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
clang/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/lib/Tooling/Refactoring/ASTSelection.cpp
clang/test/Index/error-on-deserialized.c
clang/test/SemaCXX/warn-msvc-enum-bitfield.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllSymbols.cpp b/clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllSymbols.cpp
index 7d540d83037b..70d4d7cfdff3 100644
--- a/clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllSymbols.cpp
+++ b/clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllSymbols.cpp
@@ -99,7 +99,7 @@ CreateSymbolInfo(const NamedDecl *ND, const SourceManager &SM,
SourceLocation Loc = SM.getExpansionLoc(ND->getLocation());
if (!Loc.isValid()) {
- llvm::errs() << "Declaration " << ND->getNameAsString() << "("
+ llvm::errs() << "Declaration " << ND->getDeclName() << "("
<< ND->getDeclKindName()
<< ") has invalid declaration location.";
return llvm::None;
diff --git a/clang-tools-extra/clang-move/HelperDeclRefGraph.cpp b/clang-tools-extra/clang-move/HelperDeclRefGraph.cpp
index 271bd3d6ef20..a9b773353fe6 100644
--- a/clang-tools-extra/clang-move/HelperDeclRefGraph.cpp
+++ b/clang-tools-extra/clang-move/HelperDeclRefGraph.cpp
@@ -116,7 +116,7 @@ void HelperDeclRGBuilder::run(
const auto *DC = Result.Nodes.getNodeAs<Decl>("dc");
assert(DC);
LLVM_DEBUG(llvm::dbgs() << "Find helper function usage: "
- << FuncRef->getDecl()->getNameAsString() << " ("
+ << FuncRef->getDecl()->getDeclName() << " ("
<< FuncRef->getDecl() << ")\n");
RG->addEdge(
getOutmostClassOrFunDecl(DC->getCanonicalDecl()),
@@ -126,7 +126,7 @@ void HelperDeclRGBuilder::run(
const auto *DC = Result.Nodes.getNodeAs<Decl>("dc");
assert(DC);
LLVM_DEBUG(llvm::dbgs()
- << "Find helper class usage: " << UsedClass->getNameAsString()
+ << "Find helper class usage: " << UsedClass->getDeclName()
<< " (" << UsedClass << ")\n");
RG->addEdge(getOutmostClassOrFunDecl(DC->getCanonicalDecl()), UsedClass);
}
diff --git a/clang-tools-extra/clang-move/Move.cpp b/clang-tools-extra/clang-move/Move.cpp
index 3f09f68a8046..24f819ca4ca2 100644
--- a/clang-tools-extra/clang-move/Move.cpp
+++ b/clang-tools-extra/clang-move/Move.cpp
@@ -675,8 +675,8 @@ void ClangMoveTool::run(const ast_matchers::MatchFinder::MatchResult &Result) {
Result.Nodes.getNodeAs<NamedDecl>("helper_decls")) {
MovedDecls.push_back(ND);
HelperDeclarations.push_back(ND);
- LLVM_DEBUG(llvm::dbgs() << "Add helper : " << ND->getNameAsString() << " ("
- << ND << ")\n");
+ LLVM_DEBUG(llvm::dbgs()
+ << "Add helper : " << ND->getDeclName() << " (" << ND << ")\n");
} else if (const auto *UD = Result.Nodes.getNodeAs<NamedDecl>("using_decl")) {
MovedDecls.push_back(UD);
}
@@ -735,12 +735,12 @@ void ClangMoveTool::removeDeclsInOldFiles() {
// We remove the helper declarations which are not used in the old.cc after
// moving the given declarations.
for (const auto *D : HelperDeclarations) {
- LLVM_DEBUG(llvm::dbgs() << "Check helper is used: "
- << D->getNameAsString() << " (" << D << ")\n");
+ LLVM_DEBUG(llvm::dbgs() << "Check helper is used: " << D->getDeclName()
+ << " (" << D << ")\n");
if (!UsedDecls.count(HelperDeclRGBuilder::getOutmostClassOrFunDecl(
D->getCanonicalDecl()))) {
LLVM_DEBUG(llvm::dbgs() << "Helper removed in old.cc: "
- << D->getNameAsString() << " (" << D << ")\n");
+ << D->getDeclName() << " (" << D << ")\n");
RemovedDecls.push_back(D);
}
}
@@ -820,7 +820,7 @@ void ClangMoveTool::moveDeclsToNewFiles() {
D->getCanonicalDecl())))
continue;
- LLVM_DEBUG(llvm::dbgs() << "Helper used in new.cc: " << D->getNameAsString()
+ LLVM_DEBUG(llvm::dbgs() << "Helper used in new.cc: " << D->getDeclName()
<< " " << D << "\n");
ActualNewCCDecls.push_back(D);
}
diff --git a/clang/lib/AST/ASTDiagnostic.cpp b/clang/lib/AST/ASTDiagnostic.cpp
index 05adf226bae3..99ce46e83123 100644
--- a/clang/lib/AST/ASTDiagnostic.cpp
+++ b/clang/lib/AST/ASTDiagnostic.cpp
@@ -1560,11 +1560,11 @@ class TemplateDiff {
if (!Tree.HasChildren()) {
// If we're dealing with a template specialization with zero
// arguments, there are no children; special-case this.
- OS << FromTD->getNameAsString() << "<>";
+ OS << FromTD->getDeclName() << "<>";
return;
}
- OS << FromTD->getNameAsString() << '<';
+ OS << FromTD->getDeclName() << '<';
Tree.MoveToChild();
unsigned NumElideArgs = 0;
bool AllArgsElided = true;
@@ -1724,7 +1724,7 @@ class TemplateDiff {
}
if (Same) {
- OS << "template " << FromTD->getNameAsString();
+ OS << "template " << FromTD->getDeclName();
} else if (!PrintTree) {
OS << (FromDefault ? "(default) template " : "template ");
Bold();
diff --git a/clang/lib/AST/Interp/Disasm.cpp b/clang/lib/AST/Interp/Disasm.cpp
index 293fdd4b3256..c1c18f832d4f 100644
--- a/clang/lib/AST/Interp/Disasm.cpp
+++ b/clang/lib/AST/Interp/Disasm.cpp
@@ -26,10 +26,10 @@ LLVM_DUMP_METHOD void Function::dump() const { dump(llvm::errs()); }
LLVM_DUMP_METHOD void Function::dump(llvm::raw_ostream &OS) const {
if (F) {
if (auto *Cons = dyn_cast<CXXConstructorDecl>(F)) {
- const std::string &Name = Cons->getParent()->getNameAsString();
+ DeclarationName Name = Cons->getParent()->getDeclName();
OS << Name << "::" << Name << ":\n";
} else {
- OS << F->getNameAsString() << ":\n";
+ OS << F->getDeclName() << ":\n";
}
} else {
OS << "<<expr>>\n";
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index 3d47d5cb66d2..4aae63982542 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -661,7 +661,7 @@ void TextNodeDumper::dumpBareDeclRef(const Decl *D) {
void TextNodeDumper::dumpName(const NamedDecl *ND) {
if (ND->getDeclName()) {
ColorScope Color(OS, ShowColors, DeclNameColor);
- OS << ' ' << ND->getNameAsString();
+ OS << ' ' << ND->getDeclName();
}
}
@@ -1600,9 +1600,8 @@ void TextNodeDumper::VisitFunctionDecl(const FunctionDecl *D) {
if (MD->size_overridden_methods() != 0) {
auto dumpOverride = [=](const CXXMethodDecl *D) {
SplitQualType T_split = D->getType().split();
- OS << D << " " << D->getParent()->getName()
- << "::" << D->getNameAsString() << " '"
- << QualType::getAsString(T_split, PrintPolicy) << "'";
+ OS << D << " " << D->getParent()->getName() << "::" << D->getDeclName()
+ << " '" << QualType::getAsString(T_split, PrintPolicy) << "'";
};
AddChild([=] {
@@ -2032,7 +2031,7 @@ void TextNodeDumper::VisitUsingDecl(const UsingDecl *D) {
OS << ' ';
if (D->getQualifier())
D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
- OS << D->getNameAsString();
+ OS << D->getDeclName();
}
void TextNodeDumper::VisitUnresolvedUsingTypenameDecl(
@@ -2040,7 +2039,7 @@ void TextNodeDumper::VisitUnresolvedUsingTypenameDecl(
OS << ' ';
if (D->getQualifier())
D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
- OS << D->getNameAsString();
+ OS << D->getDeclName();
}
void TextNodeDumper::VisitUnresolvedUsingValueDecl(
@@ -2048,7 +2047,7 @@ void TextNodeDumper::VisitUnresolvedUsingValueDecl(
OS << ' ';
if (D->getQualifier())
D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
- OS << D->getNameAsString();
+ OS << D->getDeclName();
dumpType(D->getType());
}
diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp
index 59a968b5c709..92654dbe8a10 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -121,7 +121,7 @@ class DeserializedDeclsChecker : public DelegatingDeserializationListener {
= Ctx.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error,
"%0 was deserialized");
Ctx.getDiagnostics().Report(Ctx.getFullLoc(D->getLocation()), DiagID)
- << ND->getNameAsString();
+ << ND;
}
DelegatingDeserializationListener::DeclRead(ID, D);
diff --git a/clang/lib/Index/FileIndexRecord.cpp b/clang/lib/Index/FileIndexRecord.cpp
index 753bdf2ce21d..df18a9aed8b7 100644
--- a/clang/lib/Index/FileIndexRecord.cpp
+++ b/clang/lib/Index/FileIndexRecord.cpp
@@ -52,7 +52,7 @@ void FileIndexRecord::print(llvm::raw_ostream &OS) const {
<< ':' << PLoc.getColumn();
if (auto ND = dyn_cast<NamedDecl>(D)) {
- OS << ' ' << ND->getNameAsString();
+ OS << ' ' << ND->getDeclName();
}
OS << '\n';
diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp
index 3b7356893833..5cc215e08ea8 100644
--- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -1849,8 +1849,8 @@ class ThreadSafetyReporter : public clang::threadSafety::ThreadSafetyHandler {
<< *PossibleMatch);
if (Verbose && POK == POK_VarAccess) {
PartialDiagnosticAt VNote(D->getLocation(),
- S.PDiag(diag::note_guarded_by_declared_here)
- << D->getNameAsString());
+ S.PDiag(diag::note_guarded_by_declared_here)
+ << D->getDeclName());
Warnings.emplace_back(std::move(Warning), getNotes(Note, VNote));
} else
Warnings.emplace_back(std::move(Warning), getNotes(Note));
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 7e73c51c7150..5c2092f1447a 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -11027,7 +11027,7 @@ static bool AnalyzeBitFieldAssignment(Sema &S, FieldDecl *Bitfield, Expr *Init,
BitfieldEnumDecl->getNumPositiveBits() > 0 &&
BitfieldEnumDecl->getNumNegativeBits() == 0) {
S.Diag(InitLoc, diag::warn_no_underlying_type_specified_for_enum_bitfield)
- << BitfieldEnumDecl->getNameAsString();
+ << BitfieldEnumDecl;
}
}
diff --git a/clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
index 1ef70b650414..56c6f8d02e0f 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
@@ -119,10 +119,10 @@ static const NoteTag *getNoteTag(CheckerContext &C,
Out << "Assuming ";
if (const auto *DRE = dyn_cast<DeclRefExpr>(Object)) {
- Out << '\'' << DRE->getDecl()->getNameAsString() << '\'';
+ Out << '\'' << DRE->getDecl()->getDeclName() << '\'';
} else if (const auto *ME = dyn_cast<MemberExpr>(Object)) {
Out << (IsKnownCast ? "Field '" : "field '")
- << ME->getMemberDecl()->getNameAsString() << '\'';
+ << ME->getMemberDecl()->getDeclName() << '\'';
} else {
Out << (IsKnownCast ? "The object" : "the object");
}
diff --git a/clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
index fc35082705fa..b2822e5307f3 100644
--- a/clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
@@ -324,7 +324,7 @@ void FuchsiaHandleChecker::checkPostCall(const CallEvent &Call,
if (auto IsInteresting = PathBR->getInterestingnessKind(RetSym)) {
std::string SBuf;
llvm::raw_string_ostream OS(SBuf);
- OS << "Function '" << FuncDecl->getNameAsString()
+ OS << "Function '" << FuncDecl->getDeclName()
<< "' returns an open handle";
return OS.str();
} else
diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index d5b0a5b2220f..fc6d15371a2f 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -3301,14 +3301,16 @@ PathDiagnosticPieceRef MallocBugVisitor::VisitNode(const ExplodedNode *N,
OS << "reallocated by call to '";
const Stmt *S = RSCurr->getStmt();
if (const auto *MemCallE = dyn_cast<CXXMemberCallExpr>(S)) {
- OS << MemCallE->getMethodDecl()->getNameAsString();
+ OS << MemCallE->getMethodDecl()->getDeclName();
} else if (const auto *OpCallE = dyn_cast<CXXOperatorCallExpr>(S)) {
- OS << OpCallE->getDirectCallee()->getNameAsString();
+ OS << OpCallE->getDirectCallee()->getDeclName();
} else if (const auto *CallE = dyn_cast<CallExpr>(S)) {
auto &CEMgr = BRC.getStateManager().getCallEventManager();
CallEventRef<> Call = CEMgr.getSimpleCall(CallE, state, CurrentLC);
- const auto *D = dyn_cast_or_null<NamedDecl>(Call->getDecl());
- OS << (D ? D->getNameAsString() : "unknown");
+ if (const auto *D = dyn_cast_or_null<NamedDecl>(Call->getDecl()))
+ OS << D->getDeclName();
+ else
+ OS << "unknown";
}
OS << "'";
StackHint = std::make_unique<StackHintGeneratorForSymbol>(
diff --git a/clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
index 7f0519c695b0..da3ce01d032b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
@@ -580,7 +580,7 @@ void MoveChecker::explainObject(llvm::raw_ostream &OS, const MemRegion *MR,
if (const auto DR =
dyn_cast_or_null<DeclRegion>(unwrapRValueReferenceIndirection(MR))) {
const auto *RegionDecl = cast<NamedDecl>(DR->getDecl());
- OS << " '" << RegionDecl->getNameAsString() << "'";
+ OS << " '" << RegionDecl->getDeclName() << "'";
}
ObjectKind OK = classifyObject(MR, RD);
diff --git a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
index 854646a8779d..1d903530201f 100644
--- a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
@@ -439,7 +439,7 @@ annotateStartParameter(const ExplodedNode *N, SymbolRef Sym,
std::string s;
llvm::raw_string_ostream os(s);
- os << "Parameter '" << PVD->getNameAsString() << "' starts at +";
+ os << "Parameter '" << PVD->getDeclName() << "' starts at +";
if (CurrT->getCount() == 1) {
os << "1, as it is marked as consuming";
} else {
diff --git a/clang/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
index f49ee5fa5ad3..1c589e3468c2 100644
--- a/clang/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
@@ -125,8 +125,8 @@ void VirtualCallChecker::checkPreCall(const CallEvent &Call,
OS << "Call to ";
if (IsPure)
OS << "pure ";
- OS << "virtual method '" << MD->getParent()->getNameAsString()
- << "::" << MD->getNameAsString() << "' during ";
+ OS << "virtual method '" << MD->getParent()->getDeclName()
+ << "::" << MD->getDeclName() << "' during ";
if (*ObState == ObjectState::CtorCalled)
OS << "construction ";
else
diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index 265dcd134213..7888029399f1 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -169,7 +169,7 @@ class ConstructedObjectKey {
if (S) {
S->printJson(Out, Helper, PP, /*AddQuotes=*/true);
} else {
- Out << '\"' << I->getAnyMember()->getNameAsString() << '\"';
+ Out << '\"' << I->getAnyMember()->getDeclName() << '\"';
}
}
diff --git a/clang/lib/Tooling/Refactoring/ASTSelection.cpp b/clang/lib/Tooling/Refactoring/ASTSelection.cpp
index af1eb491a20a..9485c8bc04ad 100644
--- a/clang/lib/Tooling/Refactoring/ASTSelection.cpp
+++ b/clang/lib/Tooling/Refactoring/ASTSelection.cpp
@@ -218,7 +218,7 @@ static void dump(const SelectedASTNode &Node, llvm::raw_ostream &OS,
if (const Decl *D = Node.Node.get<Decl>()) {
OS << D->getDeclKindName() << "Decl";
if (const auto *ND = dyn_cast<NamedDecl>(D))
- OS << " \"" << ND->getNameAsString() << '"';
+ OS << " \"" << ND->getDeclName() << '"';
} else if (const Stmt *S = Node.Node.get<Stmt>()) {
OS << S->getStmtClassName();
}
diff --git a/clang/test/Index/error-on-deserialized.c b/clang/test/Index/error-on-deserialized.c
index bf0d59a05880..78b77e5cddaa 100644
--- a/clang/test/Index/error-on-deserialized.c
+++ b/clang/test/Index/error-on-deserialized.c
@@ -10,4 +10,4 @@
// RUN: -Xclang -error-on-deserialized-decl=NestedVar1 2>&1 \
// RUN: | FileCheck %s
-// CHECK: error: NestedVar1 was deserialized
+// CHECK: error: 'NestedVar1' was deserialized
diff --git a/clang/test/SemaCXX/warn-msvc-enum-bitfield.cpp b/clang/test/SemaCXX/warn-msvc-enum-bitfield.cpp
index 99e1669018ab..496240809694 100644
--- a/clang/test/SemaCXX/warn-msvc-enum-bitfield.cpp
+++ b/clang/test/SemaCXX/warn-msvc-enum-bitfield.cpp
@@ -6,8 +6,8 @@ void test0() {
enum F { F1, F2 };
struct { E e1 : 1; E e2; F f1 : 1; F f2; } s;
- s.e1 = E1; // expected-warning {{enums in the Microsoft ABI are signed integers by default; consider giving the enum E an unsigned underlying type to make this code portable}}
- s.f1 = F1; // expected-warning {{enums in the Microsoft ABI are signed integers by default; consider giving the enum F an unsigned underlying type to make this code portable}}
+ s.e1 = E1; // expected-warning {{enums in the Microsoft ABI are signed integers by default; consider giving the enum 'E' an unsigned underlying type to make this code portable}}
+ s.f1 = F1; // expected-warning {{enums in the Microsoft ABI are signed integers by default; consider giving the enum 'F' an unsigned underlying type to make this code portable}}
s.e2 = E2;
s.f2 = F2;
More information about the cfe-commits
mailing list