[clang-tools-extra] 1b8f1a2 - [clangd] Add missing SymbolKind cases to YAML serialization (#222070)

via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 11 09:48:01 PDT 2026


Author: Andre Sun
Date: 2026-09-11T19:47:55+03:00
New Revision: 1b8f1a297004d99e7f9ad7188b8529153c693b3b

URL: https://github.com/llvm/llvm-project/commit/1b8f1a297004d99e7f9ad7188b8529153c693b3b
DIFF: https://github.com/llvm/llvm-project/commit/1b8f1a297004d99e7f9ad7188b8529153c693b3b.diff

LOG: [clangd] Add missing SymbolKind cases to YAML serialization (#222070)

The YAML index writer maps index::SymbolKind to strings through a list
of enumCase calls that was not updated when Concept, IncludeDirective,
and the template parameter kinds were added to the enum. Writing a
symbol with one of these kinds matches no case, so nothing is emitted
for the value and the next key lands on the same line, producing Kind:
Lang: C. With assertions enabled, the writer aborts rather than emitting
malformed YAML. This affects clangd-indexer --format=yaml when indexing
C++20 concepts.

Add the missing cases so the list mirrors the enum, drop the duplicate
Function entry, and add a test that round-trips every current SymbolKind
through YAML. The binary index format stores the kind as a raw byte and
is unaffected.


Fixes #206875

Added: 
    

Modified: 
    clang-tools-extra/clangd/index/YAMLSerialization.cpp
    clang-tools-extra/clangd/unittests/SerializationTests.cpp
    clang-tools-extra/docs/ReleaseNotes.md

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/index/YAMLSerialization.cpp b/clang-tools-extra/clangd/index/YAMLSerialization.cpp
index 4d6b5822ece72..e042877a469c6 100644
--- a/clang-tools-extra/clangd/index/YAMLSerialization.cpp
+++ b/clang-tools-extra/clangd/index/YAMLSerialization.cpp
@@ -265,11 +265,11 @@ template <> struct ScalarEnumerationTraits<SymbolKind> {
 #define DEFINE_ENUM(name) IO.enumCase(Value, #name, SymbolKind::name)
 
     DEFINE_ENUM(Unknown);
-    DEFINE_ENUM(Function);
     DEFINE_ENUM(Module);
     DEFINE_ENUM(Namespace);
     DEFINE_ENUM(NamespaceAlias);
     DEFINE_ENUM(Macro);
+    DEFINE_ENUM(IncludeDirective);
     DEFINE_ENUM(Enum);
     DEFINE_ENUM(Struct);
     DEFINE_ENUM(Class);
@@ -292,6 +292,10 @@ template <> struct ScalarEnumerationTraits<SymbolKind> {
     DEFINE_ENUM(ConversionFunction);
     DEFINE_ENUM(Parameter);
     DEFINE_ENUM(Using);
+    DEFINE_ENUM(TemplateTypeParm);
+    DEFINE_ENUM(TemplateTemplateParm);
+    DEFINE_ENUM(NonTypeTemplateParm);
+    DEFINE_ENUM(Concept);
 
 #undef DEFINE_ENUM
   }

diff  --git a/clang-tools-extra/clangd/unittests/SerializationTests.cpp b/clang-tools-extra/clangd/unittests/SerializationTests.cpp
index 5108e653c36a0..cbe2a9726f865 100644
--- a/clang-tools-extra/clangd/unittests/SerializationTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SerializationTests.cpp
@@ -9,6 +9,7 @@
 #include "FindSymbols.h"
 #include "Headers.h"
 #include "RIFF.h"
+#include "TestIndex.h"
 #include "index/Serialization.h"
 #include "support/Logger.h"
 #include "clang/Tooling/CompilationDatabase.h"
@@ -260,6 +261,33 @@ TEST(SerializationTest, BinaryConversions) {
               UnorderedElementsAreArray(yamlFromRelations(*In->Relations)));
 }
 
+// Every SymbolKind must have a YAML spelling, otherwise writing the index
+// produces invalid YAML (or aborts with assertions enabled).
+TEST(SerializationTest, YAMLSymbolKindRoundTrip) {
+  SymbolSlab::Builder Builder;
+  for (unsigned K = static_cast<unsigned>(index::SymbolKind::Unknown);
+       K <= static_cast<unsigned>(index::SymbolKind::Concept); ++K) {
+    std::string Name = "Sym" + std::to_string(K);
+    Symbol Sym = symbol(Name);
+    Sym.SymInfo.Kind = static_cast<index::SymbolKind>(K);
+    Builder.insert(Sym);
+  }
+  SymbolSlab Symbols = std::move(Builder).build();
+
+  IndexFileOut Out;
+  Out.Symbols = &Symbols;
+  Out.Format = IndexFileFormat::YAML;
+
+  auto In = readIndexFile(llvm::to_string(Out));
+  ASSERT_TRUE(bool(In)) << In.takeError();
+  ASSERT_TRUE(In->Symbols);
+  for (const Symbol &Sym : Symbols) {
+    auto It = In->Symbols->find(Sym.ID);
+    ASSERT_NE(It, In->Symbols->end()) << Sym.Name;
+    EXPECT_EQ(It->SymInfo.Kind, Sym.SymInfo.Kind) << Sym.Name;
+  }
+}
+
 TEST(SerializationTest, SrcsTest) {
   auto In = readIndexFile(YAML);
   EXPECT_TRUE(bool(In)) << In.takeError();

diff  --git a/clang-tools-extra/docs/ReleaseNotes.md b/clang-tools-extra/docs/ReleaseNotes.md
index a883363fd0775..e865792b05ff5 100644
--- a/clang-tools-extra/docs/ReleaseNotes.md
+++ b/clang-tools-extra/docs/ReleaseNotes.md
@@ -95,6 +95,10 @@ infrastructure are described first, followed by tool-specific sections.
 
 #### Miscellaneous
 
+- Fixed `clangd-indexer --format=yaml` emitting invalid YAML when indexing
+  C++20 concepts.
+  ([#206875](https://github.com/llvm/llvm-project/issues/206875))
+
 ### Improvements to clang-doc
 
 ### Improvements to clang-query


        


More information about the cfe-commits mailing list