[clang-tools-extra] 57bfe25 - [clangd] Remove reundant use of getSpellingLoc()

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 20 11:52:28 PDT 2023


Author: Nathan Ridge
Date: 2023-03-20T14:52:10-04:00
New Revision: 57bfe25574a0bfa9b6701e645d1f1ec966f838d9

URL: https://github.com/llvm/llvm-project/commit/57bfe25574a0bfa9b6701e645d1f1ec966f838d9
DIFF: https://github.com/llvm/llvm-project/commit/57bfe25574a0bfa9b6701e645d1f1ec966f838d9.diff

LOG: [clangd] Remove reundant use of getSpellingLoc()

getFileLoc() is guaranteed to return a file loc, and getSpellingLoc()
on a file loc is a no-op.

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

Added: 
    

Modified: 
    clang-tools-extra/clangd/FindSymbols.cpp
    clang-tools-extra/clangd/XRefs.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/FindSymbols.cpp b/clang-tools-extra/clangd/FindSymbols.cpp
index 2eab7ca27033..790ee9af8f4a 100644
--- a/clang-tools-extra/clangd/FindSymbols.cpp
+++ b/clang-tools-extra/clangd/FindSymbols.cpp
@@ -223,8 +223,8 @@ std::string getSymbolDetail(ASTContext &Ctx, const NamedDecl &ND) {
 std::optional<DocumentSymbol> declToSym(ASTContext &Ctx, const NamedDecl &ND) {
   auto &SM = Ctx.getSourceManager();
 
-  SourceLocation BeginLoc = SM.getSpellingLoc(SM.getFileLoc(ND.getBeginLoc()));
-  SourceLocation EndLoc = SM.getSpellingLoc(SM.getFileLoc(ND.getEndLoc()));
+  SourceLocation BeginLoc = SM.getFileLoc(ND.getBeginLoc());
+  SourceLocation EndLoc = SM.getFileLoc(ND.getEndLoc());
   const auto SymbolRange =
       toHalfOpenFileRange(SM, Ctx.getLangOpts(), {BeginLoc, EndLoc});
   if (!SymbolRange)

diff  --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp
index 1b1220c8aa7a..d4442c11a8ed 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -1611,8 +1611,8 @@ declToHierarchyItem(const NamedDecl &ND, llvm::StringRef TUPath) {
   ASTContext &Ctx = ND.getASTContext();
   auto &SM = Ctx.getSourceManager();
   SourceLocation NameLoc = nameLocation(ND, Ctx.getSourceManager());
-  SourceLocation BeginLoc = SM.getSpellingLoc(SM.getFileLoc(ND.getBeginLoc()));
-  SourceLocation EndLoc = SM.getSpellingLoc(SM.getFileLoc(ND.getEndLoc()));
+  SourceLocation BeginLoc = SM.getFileLoc(ND.getBeginLoc());
+  SourceLocation EndLoc = SM.getFileLoc(ND.getEndLoc());
   const auto DeclRange =
       toHalfOpenFileRange(SM, Ctx.getLangOpts(), {BeginLoc, EndLoc});
   if (!DeclRange)


        


More information about the cfe-commits mailing list