[PATCH] D73369: [clangd] Simplify "preferred" vs "definition" logic a bit in XRefs AST code.

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 27 06:58:30 PST 2020


kadircet added inline comments.


================
Comment at: clang-tools-extra/clangd/XRefs.cpp:257
     const NamedDecl *Def = getDefinition(D);
-    const NamedDecl *Preferred = Def ? Def : D;
+    if (const NamedDecl *C = llvm::dyn_cast<NamedDecl>(D->getCanonicalDecl()))
+      D = C;
----------------
Is it possible for this check to ever fail? I think it is safe to just perform a `llvm::cast` instead of `dyn_cast`.
also why not perform this before getting definition?


================
Comment at: clang-tools-extra/clangd/XRefs.cpp:278
     Result.back().PreferredDeclaration = *Loc;
-    // Preferred is always a definition if possible, so this check works.
-    if (Def == Preferred)
-      Result.back().Definition = *Loc;
+    if (Def)
+      Result.back().Definition = makeLocation(
----------------
maybe inline `getDefinition` to here


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73369/new/

https://reviews.llvm.org/D73369





More information about the cfe-commits mailing list