https://github.com/hongtaihu created https://github.com/llvm/llvm-project/pull/212134
Fixes #200571. Sema error recovery can produce special declaration names containing qualified types, e.g. `operator std::align_val_t`. IncludeFixer forwarded these names as `FuzzyFindRequest::Query`, but fuzzy-find queries must be unqualified. This triggers an assertion in `MemIndex`. Skip include fixing for unresolved names that cannot be represented as an unqualified query plus scopes. The original diagnostic is left unchanged. We intentionally do not attempt to normalize these recovery-generated names: they may encode special declaration-name semantics, and inserting a header alone cannot in general repair the corresponding source spelling. Add a regression test for the malformed conversion-operator recovery path. Testing: - `build-clangd-20260726/tools/clang/tools/extra/clangd/unittests/ClangdTests --gtest_filter='IncludeFixerTest.NoCrashOnQualifiedConversionOperatorName' --gtest_color=no` - passes; the regression path no longer asserts. >From 168f039b80d5729c0d2c4d93942787dc17975455 Mon Sep 17 00:00:00 2001 From: hongtaihu <[email protected]> Date: Mon, 27 Jul 2026 01:07:59 +0800 Subject: [PATCH] [clangd] Avoid invalid include-fixer fuzzy-find queries --- clang-tools-extra/clangd/IncludeFixer.cpp | 6 ++++++ .../clangd/unittests/DiagnosticsTests.cpp | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/clang-tools-extra/clangd/IncludeFixer.cpp b/clang-tools-extra/clangd/IncludeFixer.cpp index 5ecf853524a3f..cb65ac82446f8 100644 --- a/clang-tools-extra/clangd/IncludeFixer.cpp +++ b/clang-tools-extra/clangd/IncludeFixer.cpp @@ -559,6 +559,12 @@ std::vector<Fix> IncludeFixer::fixUnresolvedName() const { vlog("Trying to fix unresolved name \"{0}\" in scopes: [{1}]", Unresolved.Name, llvm::join(Unresolved.Scopes, ", ")); + // FuzzyFind only supports unqualified queries. Sema recovery may produce + // special declaration names, such as conversion operators with qualified + // types, that cannot be represented as a query plus scopes. + if (llvm::StringRef(Unresolved.Name).contains("::")) + return {}; + FuzzyFindRequest Req; Req.AnyScope = false; Req.Query = Unresolved.Name; diff --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp index 6d91ac1ef1e8e..3d85e6c285f50 100644 --- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp +++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp @@ -1560,6 +1560,19 @@ TEST(IncludeFixerTest, NoCrashMemberAccess) { UnorderedElementsAre(Diag(Test.range(), "no member named 'xy' in 'X'"))); } +TEST(IncludeFixerTest, NoCrashOnQualifiedConversionOperatorName) { + auto TU = TestTU::withCode(R"cpp(// error-ok +namespace std {} +void f() { operator new[](0, operator::align_val_t{}); } + )cpp"); + TU.ExtraArgs.push_back("-std=c++17"); + auto Index = buildIndexWithSymbol( + SymbolWithHeader{"std::align_val_t", "unittest:///new.h", "<new>"}); + TU.ExternalIndex = Index.get(); + + EXPECT_THAT(TU.build().getDiagnostics(), Not(IsEmpty())); +} + TEST(IncludeFixerTest, UseCachedIndexResults) { // As index results for the identical request are cached, more than 5 fixes // are generated. _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
