[PATCH] D77222: [clangd] Fix an assertion crash in ReferenceFinder.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 2 01:03:33 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb42006596905: [clangd] Fix an assertion crash in ReferenceFinder. (authored by hokein).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D77222/new/
https://reviews.llvm.org/D77222
Files:
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/clangd/unittests/XRefsTests.cpp
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1121,6 +1121,30 @@
}
}
+TEST(FindReferences, MainFileReferencesOnly) {
+ llvm::StringRef Test =
+ R"cpp(
+ void test() {
+ int [[fo^o]] = 1;
+ // refs not from main file should not be included.
+ #include "foo.inc"
+ })cpp";
+
+ Annotations Code(Test);
+ auto TU = TestTU::withCode(Code.code());
+ TU.AdditionalFiles["foo.inc"] = R"cpp(
+ foo = 3;
+ )cpp";
+ auto AST = TU.build();
+
+ std::vector<Matcher<Location>> ExpectedLocations;
+ for (const auto &R : Code.ranges())
+ ExpectedLocations.push_back(RangeIs(R));
+ EXPECT_THAT(findReferences(AST, Code.point(), 0).References,
+ ElementsAreArray(ExpectedLocations))
+ << Test;
+}
+
TEST(FindReferences, ExplicitSymbols) {
const char *Tests[] = {
R"cpp(
Index: clang-tools-extra/clangd/XRefs.cpp
===================================================================
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -583,13 +583,11 @@
SourceLocation Loc,
index::IndexDataConsumer::ASTNodeInfo ASTNode) override {
assert(D->isCanonicalDecl() && "expect D to be a canonical declaration");
- if (!CanonicalTargets.count(D))
+ const SourceManager &SM = AST.getSourceManager();
+ if (!CanonicalTargets.count(D) || !isInsideMainFile(Loc, SM))
return true;
const auto &TB = AST.getTokens();
- const SourceManager &SM = AST.getSourceManager();
Loc = SM.getFileLoc(Loc);
- // We are only traversing decls *inside* the main file, so this should hold.
- assert(isInsideMainFile(Loc, SM));
if (const auto *Tok = TB.spelledTokenAt(Loc))
References.push_back({*Tok, Roles});
return true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77222.254443.patch
Type: text/x-patch
Size: 1997 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200402/d3af6ecd/attachment.bin>
More information about the cfe-commits
mailing list