[clang-tools-extra] [clang-doc] fix flaky test in clang-doc (PR #101387)

via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 1 13:04:47 PDT 2024


https://github.com/PeterChou1 updated https://github.com/llvm/llvm-project/pull/101387

>From 3ec4d5b9e5bc24bfb466d65fd9c45c51fa6d3e94 Mon Sep 17 00:00:00 2001
From: PeterChou1 <peter.chou at mail.utoronto.ca>
Date: Wed, 31 Jul 2024 14:52:11 -0400
Subject: [PATCH 01/13] [clang-doc] uncomment unsupported

---
 clang-tools-extra/test/clang-doc/basic-project.test | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/clang-tools-extra/test/clang-doc/basic-project.test b/clang-tools-extra/test/clang-doc/basic-project.test
index 38569d824f1f0..51d3ac6ce6dcd 100644
--- a/clang-tools-extra/test/clang-doc/basic-project.test
+++ b/clang-tools-extra/test/clang-doc/basic-project.test
@@ -1,6 +1,3 @@
-// See https://github.com/llvm/llvm-project/issues/97507.
-// UNSUPPORTED: target={{.*}}
-
 // RUN: rm -rf %t && mkdir -p %t/docs %t/build
 // RUN: sed 's|$test_dir|%/S|g' %S/Inputs/basic-project/database_template.json > %t/build/compile_commands.json
 // RUN: clang-doc --format=html --output=%t/docs --executor=all-TUs %t/build/compile_commands.json

>From 114a5721e593a9b57ef31ed9856d0bce4a62da94 Mon Sep 17 00:00:00 2001
From: PeterChou1 <peter.chou at mail.utoronto.ca>
Date: Thu, 1 Aug 2024 03:24:42 -0400
Subject: [PATCH 02/13] [clang-doc] fix non-determinism

---
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 3363cafeded5e..9a540a5061b6a 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -287,7 +287,14 @@ Example usage for a project using a compile commands database:
         auto R = USRToBitcode.try_emplace(Key, std::vector<StringRef>());
         R.first->second.emplace_back(Value);
       });
-
+  
+  for (auto &Entry : USRToBitcode) {
+    std::vector<llvm::StringRef> &Bitcode = Entry.second;
+    std::sort(Bitcode.begin(), Bitcode.end(),
+              [](const llvm::StringRef &A, const llvm::StringRef &B) {
+                return A < B;
+              });
+  }
   // Collects all Infos according to their unique USR value. This map is added
   // to from the thread pool below and is protected by the USRToInfoMutex.
   llvm::sys::Mutex USRToInfoMutex;

>From 556adbf8e1219d73c4ae859036be7ac21abd3762 Mon Sep 17 00:00:00 2001
From: PeterChou1 <peter.chou at mail.utoronto.ca>
Date: Thu, 1 Aug 2024 04:11:45 -0400
Subject: [PATCH 03/13] [clang-doc] fix tests

---
 .../test/clang-doc/basic-project.test         | 12 +++----
 .../test/clang-doc/namespace.cpp              |  6 ++--
 .../test/clang-doc/templates.cpp              | 34 +++++++++----------
 3 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/clang-tools-extra/test/clang-doc/basic-project.test b/clang-tools-extra/test/clang-doc/basic-project.test
index 51d3ac6ce6dcd..ee80493f6d7fa 100644
--- a/clang-tools-extra/test/clang-doc/basic-project.test
+++ b/clang-tools-extra/test/clang-doc/basic-project.test
@@ -73,12 +73,12 @@
 // HTML-CALC:  <h3 id="{{([0-9A-F]{40})}}">add</h3>
 // HTML-CALC:  <p>public int add(int a, int b)</p>
 // HTML-CALC:  <p>Defined at line 3 of file {{.*}}Calculator.cpp</p>
-// HTML-CALC:  <h3 id="{{([0-9A-F]{40})}}">subtract</h3>
-// HTML-CALC:  <p>public int subtract(int a, int b)</p>
-// HTML-CALC:  <p>Defined at line 7 of file {{.*}}Calculator.cpp</p>
 // HTML-CALC:  <h3 id="{{([0-9A-F]{40})}}">multiply</h3>
 // HTML-CALC:  <p>public int multiply(int a, int b)</p>
 // HTML-CALC:  <p>Defined at line 11 of file {{.*}}Calculator.cpp</p>
+// HTML-CALC:  <h3 id="{{([0-9A-F]{40})}}">subtract</h3>
+// HTML-CALC:  <p>public int subtract(int a, int b)</p>
+// HTML-CALC:  <p>Defined at line 7 of file {{.*}}Calculator.cpp</p>
 // HTML-CALC:  <h3 id="{{([0-9A-F]{40})}}">divide</h3>
 // HTML-CALC:  <p>public double divide(int a, int b)</p>
 // HTML-CALC:  <p>Defined at line 15 of file {{.*}}Calculator.cpp</p>
@@ -114,15 +114,15 @@
 // HTML-CIRCLE: <h2 id="Members">Members</h2>
 // HTML-CIRCLE: <li>private double radius_</li>
 // HTML-CIRCLE: <h2 id="Functions">Functions</h2>
-// HTML-CIRCLE: <h3 id="{{([0-9A-F]{40})}}">Circle</h3>
-// HTML-CIRCLE: <p>public void Circle(double radius)</p>
-// HTML-CIRCLE: <p>Defined at line 3 of file {{.*}}Circle.cpp</p>
 // HTML-CIRCLE: <h3 id="{{([0-9A-F]{40})}}">area</h3>
 // HTML-CIRCLE: <p>public double area()</p>
 // HTML-CIRCLE: <p>Defined at line 5 of file {{.*}}Circle.cpp</p>
 // HTML-CIRCLE: <h3 id="{{([0-9A-F]{40})}}">perimeter</h3>
 // HTML-CIRCLE: <p>public double perimeter()</p>
 // HTML-CIRCLE: <p>Defined at line 9 of file {{.*}}Circle.cpp</p>
+// HTML-CIRCLE: <h3 id="{{([0-9A-F]{40})}}">Circle</h3>
+// HTML-CIRCLE: <p>public void Circle(double radius)</p>
+// HTML-CIRCLE: <p>Defined at line 3 of file {{.*}}Circle.cpp</p>
 
 // MD-CALC: # class Calculator
 // MD-CALC: *Defined at .{{[\/]}}include{{[\/]}}Calculator.h#8*
diff --git a/clang-tools-extra/test/clang-doc/namespace.cpp b/clang-tools-extra/test/clang-doc/namespace.cpp
index 12f3cb8a84bc6..4881f942fe52a 100644
--- a/clang-tools-extra/test/clang-doc/namespace.cpp
+++ b/clang-tools-extra/test/clang-doc/namespace.cpp
@@ -271,15 +271,15 @@ namespace AnotherNamespace {
 // HTML-GLOBAL-INDEX: <div id="main-content" class="col-xs-12 col-sm-9 col-md-8 main-content">
 // HTML-GLOBAL-INDEX: <h1>Global Namespace</h1>
 // HTML-GLOBAL-INDEX: <h2 id="Namespaces">Namespaces</h2>
-// HTML-GLOBAL-INDEX: <li>@nonymous_namespace</li>
 // HTML-GLOBAL-INDEX: <li>PrimaryNamespace</li>
 // HTML-GLOBAL-INDEX: <li>AnotherNamespace</li>
+// HTML-GLOBAL-INDEX: <li>@nonymous_namespace</li>
 
 // MD-GLOBAL-INDEX: # Global Namespace
 // MD-GLOBAL-INDEX: ## Namespaces
-// MD-GLOBAL-INDEX: * [@nonymous_namespace](..{{[\/]}}@nonymous_namespace{{[\/]}}index.md)
 // MD-GLOBAL-INDEX: * [PrimaryNamespace](..{{[\/]}}PrimaryNamespace{{[\/]}}index.md)
 // MD-GLOBAL-INDEX: * [AnotherNamespace](..{{[\/]}}AnotherNamespace{{[\/]}}index.md)
+// MD-GLOBAL-INDEX: * [@nonymous_namespace](..{{[\/]}}@nonymous_namespace{{[\/]}}index.md)
 
 // MD-ALL-FILES: # All Files
 // MD-ALL-FILES: ## [@nonymous_namespace](@nonymous_namespace{{[\/]}}index.md)
@@ -290,4 +290,4 @@ namespace AnotherNamespace {
 // MD-INDEX: #  C/C++ Reference
 // MD-INDEX: * Namespace: [@nonymous_namespace](@nonymous_namespace)
 // MD-INDEX: * Namespace: [AnotherNamespace](AnotherNamespace)
-// MD-INDEX: * Namespace: [PrimaryNamespace](PrimaryNamespace)
\ No newline at end of file
+// MD-INDEX: * Namespace: [PrimaryNamespace](PrimaryNamespace)
diff --git a/clang-tools-extra/test/clang-doc/templates.cpp b/clang-tools-extra/test/clang-doc/templates.cpp
index 2e04a77ac9e62..4d4a25b8d3b82 100644
--- a/clang-tools-extra/test/clang-doc/templates.cpp
+++ b/clang-tools-extra/test/clang-doc/templates.cpp
@@ -18,6 +18,23 @@ void ParamPackFunction(T... args);
 // CHECK: ---
 // CHECK-NEXT: USR:             '{{([0-9A-F]{40})}}'
 // CHECK-NEXT: ChildFunctions:
+// CHECK-NEXT:  - USR:             '{{([0-9A-F]{40})}}'
+// CHECK-NEXT:    Name:            'ParamPackFunction'
+// CHECK-NEXT:    Location:
+// CHECK-NEXT:      - LineNumber:      16
+// CHECK-NEXT:        Filename:        '{{.*}}'
+// CHECK-NEXT:    Params:
+// CHECK-NEXT:      - Type:
+// CHECK-NEXT:          Name:            'T...'
+// CHECK-NEXT:          QualName:        'T...'
+// CHECK-NEXT:        Name:            'args'
+// CHECK-NEXT:    ReturnType:
+// CHECK-NEXT:      Type:
+// CHECK-NEXT:        Name:            'void'
+// CHECK-NEXT:        QualName:        'void'
+// CHECK-NEXT:    Template:
+// CHECK-NEXT:      Params:
+// CHECK-NEXT:        - Contents:        'class... T'
 // CHECK-NEXT:   - USR:             '{{([0-9A-F]{40})}}'
 // CHECK-NEXT:     Name:            'function'
 // CHECK-NEXT:     DefLocation:
@@ -56,21 +73,4 @@ void ParamPackFunction(T... args);
 // CHECK-NEXT:         Params:
 // CHECK-NEXT:           - Contents:        'bool'
 // CHECK-NEXT:           - Contents:        '0'
-// CHECK-NEXT:  - USR:             '{{([0-9A-F]{40})}}'
-// CHECK-NEXT:    Name:            'ParamPackFunction'
-// CHECK-NEXT:    Location:
-// CHECK-NEXT:      - LineNumber:      16
-// CHECK-NEXT:        Filename:        '{{.*}}'
-// CHECK-NEXT:    Params:
-// CHECK-NEXT:      - Type:
-// CHECK-NEXT:          Name:            'T...'
-// CHECK-NEXT:          QualName:        'T...'
-// CHECK-NEXT:        Name:            'args'
-// CHECK-NEXT:    ReturnType:
-// CHECK-NEXT:      Type:
-// CHECK-NEXT:        Name:            'void'
-// CHECK-NEXT:        QualName:        'void'
-// CHECK-NEXT:    Template:
-// CHECK-NEXT:      Params:
-// CHECK-NEXT:        - Contents:        'class... T'
 // CHECK-NEXT: ...

>From ff69b599db0db06ec609e1231ff6d75a91cade16 Mon Sep 17 00:00:00 2001
From: PeterChou1 <peter.chou at mail.utoronto.ca>
Date: Thu, 1 Aug 2024 05:49:42 -0400
Subject: [PATCH 04/13] [clang-doc] clang-format

---
 clang-tools-extra/clang-doc/CMakeLists.txt    | 43 +++++--------------
 clang-tools-extra/clang-doc/HTMLGenerator.cpp | 14 +++---
 .../clang-doc/Representation.cpp              |  9 +++-
 clang-tools-extra/clang-doc/Representation.h  | 17 +++++++-
 clang-tools-extra/clang-doc/Serialize.cpp     |  4 +-
 .../clang-doc/tool/ClangDocMain.cpp           | 25 ++++++++---
 .../test/clang-doc/basic-project.test         | 13 +++---
 .../test/clang-doc/namespace.cpp              |  4 +-
 .../test/clang-doc/templates.cpp              | 34 +++++++--------
 9 files changed, 86 insertions(+), 77 deletions(-)

diff --git a/clang-tools-extra/clang-doc/CMakeLists.txt b/clang-tools-extra/clang-doc/CMakeLists.txt
index 975ad8e242e49..ec6b51f51563f 100644
--- a/clang-tools-extra/clang-doc/CMakeLists.txt
+++ b/clang-tools-extra/clang-doc/CMakeLists.txt
@@ -1,37 +1,14 @@
-set(LLVM_LINK_COMPONENTS
-  support
-  BitstreamReader
-  FrontendOpenMP
-  )
+set(LLVM_LINK_COMPONENTS support BitstreamReader FrontendOpenMP)
 
-add_clang_library(clangDoc
-  BitcodeReader.cpp
-  BitcodeWriter.cpp
-  ClangDoc.cpp
-  Generators.cpp
-  HTMLGenerator.cpp
-  Mapper.cpp
-  MDGenerator.cpp
-  Representation.cpp
-  Serialize.cpp
-  YAMLGenerator.cpp
+    add_clang_library(
+        clangDoc BitcodeReader.cpp BitcodeWriter.cpp ClangDoc.cpp Generators
+            .cpp HTMLGenerator.cpp Mapper.cpp MDGenerator.cpp Representation
+            .cpp Serialize.cpp YAMLGenerator.cpp
 
-  DEPENDS
-  omp_gen
-  ClangDriverOptions
-)
+                DEPENDS omp_gen ClangDriverOptions)
 
-clang_target_link_libraries(clangDoc
-  PRIVATE
-  clangAnalysis
-  clangAST
-  clangASTMatchers
-  clangBasic
-  clangFrontend
-  clangIndex
-  clangLex
-  clangTooling
-  clangToolingCore
-  )
+        clang_target_link_libraries(
+            clangDoc PRIVATE clangAnalysis clangAST clangASTMatchers clangBasic
+                clangFrontend clangIndex clangLex clangTooling clangToolingCore)
 
-add_subdirectory(tool)
+            add_subdirectory(tool)
diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index aef22453035c3..036e628d6e8fa 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -619,7 +619,7 @@ static std::unique_ptr<HTMLNode> genHTML(const CommentInfo &I) {
     }
     return std::move(FullComment);
   }
- 
+
   if (I.Kind == "ParagraphComment") {
     auto ParagraphComment = std::make_unique<TagNode>(HTMLTag::TAG_P);
     for (const auto &Child : I.Children) {
@@ -667,8 +667,8 @@ genHTML(const EnumInfo &I, const ClangDocContext &CDCtx) {
     if (!CDCtx.RepositoryUrl)
       Out.emplace_back(writeFileDefinition(*I.DefLoc));
     else
-      Out.emplace_back(writeFileDefinition(
-          *I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
+      Out.emplace_back(
+          writeFileDefinition(*I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
   }
 
   std::string Description;
@@ -716,8 +716,8 @@ genHTML(const FunctionInfo &I, const ClangDocContext &CDCtx,
     if (!CDCtx.RepositoryUrl)
       Out.emplace_back(writeFileDefinition(*I.DefLoc));
     else
-      Out.emplace_back(writeFileDefinition(
-          *I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
+      Out.emplace_back(
+          writeFileDefinition(*I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
   }
 
   std::string Description;
@@ -783,8 +783,8 @@ genHTML(const RecordInfo &I, Index &InfoIndex, const ClangDocContext &CDCtx,
     if (!CDCtx.RepositoryUrl)
       Out.emplace_back(writeFileDefinition(*I.DefLoc));
     else
-      Out.emplace_back(writeFileDefinition(
-          *I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
+      Out.emplace_back(
+          writeFileDefinition(*I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
   }
 
   std::string Description;
diff --git a/clang-tools-extra/clang-doc/Representation.cpp b/clang-tools-extra/clang-doc/Representation.cpp
index d08afbb962189..726ad93aeb715 100644
--- a/clang-tools-extra/clang-doc/Representation.cpp
+++ b/clang-tools-extra/clang-doc/Representation.cpp
@@ -221,7 +221,7 @@ void SymbolInfo::merge(SymbolInfo &&Other) {
 }
 
 NamespaceInfo::NamespaceInfo(SymbolID USR, StringRef Name, StringRef Path)
-      : Info(InfoType::IT_namespace, USR, Name, Path) {}
+    : Info(InfoType::IT_namespace, USR, Name, Path) {}
 
 void NamespaceInfo::merge(NamespaceInfo &&Other) {
   assert(mergeable(Other));
@@ -384,5 +384,12 @@ ClangDocContext::ClangDocContext(tooling::ExecutionContext *ECtx,
   }
 }
 
+void ScopeChildren::sort() {
+  std::sort(Namespaces.begin(), Namespaces.end());
+  std::sort(Records.begin(), Records.end());
+  std::sort(Functions.begin(), Functions.end());
+  std::sort(Enums.begin(), Enums.end());
+  std::sort(Typedefs.begin(), Typedefs.end());
+}
 } // namespace doc
 } // namespace clang
diff --git a/clang-tools-extra/clang-doc/Representation.h b/clang-tools-extra/clang-doc/Representation.h
index d70c279f7a2bd..058687572f481 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -104,6 +104,9 @@ struct Reference {
 
   bool mergeable(const Reference &Other);
   void merge(Reference &&I);
+  bool operator<(const Reference &Other) const {
+    return llvm::toStringRef(USR) < llvm::toStringRef(Other.USR);
+  }
 
   /// Returns the path for this Reference relative to CurrentPath.
   llvm::SmallString<64> getRelativeFilePath(const StringRef &CurrentPath) const;
@@ -145,6 +148,8 @@ struct ScopeChildren {
   std::vector<FunctionInfo> Functions;
   std::vector<EnumInfo> Enums;
   std::vector<TypedefInfo> Typedefs;
+
+  void sort();
 };
 
 // A base struct for TypeInfos
@@ -270,10 +275,12 @@ struct Info {
 
   virtual ~Info() = default;
 
+  Info &operator=(Info &&Other) = default;
+
   SymbolID USR =
       SymbolID(); // Unique identifier for the decl described by this Info.
-  const InfoType IT = InfoType::IT_default; // InfoType of this particular Info.
-  SmallString<16> Name;                     // Unqualified name of the decl.
+  InfoType IT = InfoType::IT_default; // InfoType of this particular Info.
+  SmallString<16> Name;               // Unqualified name of the decl.
   llvm::SmallVector<Reference, 4>
       Namespace; // List of parent namespaces for this decl.
   std::vector<CommentInfo> Description; // Comment description of this decl.
@@ -312,6 +319,12 @@ struct SymbolInfo : public Info {
 
   std::optional<Location> DefLoc;     // Location where this decl is defined.
   llvm::SmallVector<Location, 2> Loc; // Locations where this decl is declared.
+
+  bool operator<(const SymbolInfo &Other) const {
+    assert(Loc.size() > 0 && Other.Loc.size() > 0 &&
+           "SymbolInfo must have at least one location");
+    return Loc[0] < Other.Loc[0];
+  }
 };
 
 // TODO: Expand to allow for documenting templating and default args.
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp
index 3b074d849e8a9..a0eeb312024f0 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -558,7 +558,7 @@ static void populateFunctionInfo(FunctionInfo &I, const FunctionDecl *D,
 static void populateMemberTypeInfo(MemberTypeInfo &I, const FieldDecl *D) {
   assert(D && "Expect non-null FieldDecl in populateMemberTypeInfo");
 
-  ASTContext& Context = D->getASTContext();
+  ASTContext &Context = D->getASTContext();
   // TODO investigate whether we can use ASTContext::getCommentForDecl instead
   // of this logic. See also similar code in Mapper.cpp.
   RawComment *Comment = Context.getRawCommentForDeclNoCache(D);
@@ -566,7 +566,7 @@ static void populateMemberTypeInfo(MemberTypeInfo &I, const FieldDecl *D) {
     return;
 
   Comment->setAttached();
-  if (comments::FullComment* fc = Comment->parse(Context, nullptr, D)) {
+  if (comments::FullComment *fc = Comment->parse(Context, nullptr, D)) {
     I.Description.emplace_back();
     parseFullComment(fc, I.Description.back());
   }
diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 9a540a5061b6a..48179bd3d5238 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -205,6 +205,22 @@ llvm::Error getHtmlAssetFiles(const char *Argv0,
   return getDefaultAssetFiles(Argv0, CDCtx);
 }
 
+/// Make the output of clang-doc deterministic by sorting the children of
+/// namespaces and records.
+void sortUsrToInfo(llvm::StringMap<std::unique_ptr<doc::Info>>& USRToInfo) {
+  for (auto &I : USRToInfo) {
+    auto &Info = I.second;
+    if (Info->IT == doc::InfoType::IT_namespace) {
+      auto *Namespace = static_cast<clang::doc::NamespaceInfo *>(Info.get());
+      Namespace->Children.sort();
+    }
+    if (Info->IT == doc::InfoType::IT_record) {
+        auto *Record = static_cast<clang::doc::RecordInfo *>(Info.get());
+        Record->Children.sort();
+    }
+  }
+}
+
 int main(int argc, const char **argv) {
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
   std::error_code OK;
@@ -288,13 +304,6 @@ Example usage for a project using a compile commands database:
         R.first->second.emplace_back(Value);
       });
   
-  for (auto &Entry : USRToBitcode) {
-    std::vector<llvm::StringRef> &Bitcode = Entry.second;
-    std::sort(Bitcode.begin(), Bitcode.end(),
-              [](const llvm::StringRef &A, const llvm::StringRef &B) {
-                return A < B;
-              });
-  }
   // Collects all Infos according to their unique USR value. This map is added
   // to from the thread pool below and is protected by the USRToInfoMutex.
   llvm::sys::Mutex USRToInfoMutex;
@@ -348,6 +357,8 @@ Example usage for a project using a compile commands database:
   if (Error)
     return 1;
 
+  sortUsrToInfo(USRToInfo);
+
   // Ensure the root output directory exists.
   if (std::error_code Err = llvm::sys::fs::create_directories(OutDirectory);
       Err != std::error_code()) {
diff --git a/clang-tools-extra/test/clang-doc/basic-project.test b/clang-tools-extra/test/clang-doc/basic-project.test
index ee80493f6d7fa..2d8e3be4bd504 100644
--- a/clang-tools-extra/test/clang-doc/basic-project.test
+++ b/clang-tools-extra/test/clang-doc/basic-project.test
@@ -73,12 +73,12 @@
 // HTML-CALC:  <h3 id="{{([0-9A-F]{40})}}">add</h3>
 // HTML-CALC:  <p>public int add(int a, int b)</p>
 // HTML-CALC:  <p>Defined at line 3 of file {{.*}}Calculator.cpp</p>
-// HTML-CALC:  <h3 id="{{([0-9A-F]{40})}}">multiply</h3>
-// HTML-CALC:  <p>public int multiply(int a, int b)</p>
-// HTML-CALC:  <p>Defined at line 11 of file {{.*}}Calculator.cpp</p>
 // HTML-CALC:  <h3 id="{{([0-9A-F]{40})}}">subtract</h3>
 // HTML-CALC:  <p>public int subtract(int a, int b)</p>
 // HTML-CALC:  <p>Defined at line 7 of file {{.*}}Calculator.cpp</p>
+// HTML-CALC:  <h3 id="{{([0-9A-F]{40})}}">multiply</h3>
+// HTML-CALC:  <p>public int multiply(int a, int b)</p>
+// HTML-CALC:  <p>Defined at line 11 of file {{.*}}Calculator.cpp</p>
 // HTML-CALC:  <h3 id="{{([0-9A-F]{40})}}">divide</h3>
 // HTML-CALC:  <p>public double divide(int a, int b)</p>
 // HTML-CALC:  <p>Defined at line 15 of file {{.*}}Calculator.cpp</p>
@@ -114,15 +114,16 @@
 // HTML-CIRCLE: <h2 id="Members">Members</h2>
 // HTML-CIRCLE: <li>private double radius_</li>
 // HTML-CIRCLE: <h2 id="Functions">Functions</h2>
+// HTML-CIRCLE: <h3 id="{{([0-9A-F]{40})}}">Circle</h3>
+// HTML-CIRCLE: <p>public void Circle(double radius)</p>
+// HTML-CIRCLE: <p>Defined at line 3 of file {{.*}}Circle.cpp</p>
 // HTML-CIRCLE: <h3 id="{{([0-9A-F]{40})}}">area</h3>
 // HTML-CIRCLE: <p>public double area()</p>
 // HTML-CIRCLE: <p>Defined at line 5 of file {{.*}}Circle.cpp</p>
 // HTML-CIRCLE: <h3 id="{{([0-9A-F]{40})}}">perimeter</h3>
 // HTML-CIRCLE: <p>public double perimeter()</p>
 // HTML-CIRCLE: <p>Defined at line 9 of file {{.*}}Circle.cpp</p>
-// HTML-CIRCLE: <h3 id="{{([0-9A-F]{40})}}">Circle</h3>
-// HTML-CIRCLE: <p>public void Circle(double radius)</p>
-// HTML-CIRCLE: <p>Defined at line 3 of file {{.*}}Circle.cpp</p>
+
 
 // MD-CALC: # class Calculator
 // MD-CALC: *Defined at .{{[\/]}}include{{[\/]}}Calculator.h#8*
diff --git a/clang-tools-extra/test/clang-doc/namespace.cpp b/clang-tools-extra/test/clang-doc/namespace.cpp
index 4881f942fe52a..72ed277a2c1e9 100644
--- a/clang-tools-extra/test/clang-doc/namespace.cpp
+++ b/clang-tools-extra/test/clang-doc/namespace.cpp
@@ -271,15 +271,15 @@ namespace AnotherNamespace {
 // HTML-GLOBAL-INDEX: <div id="main-content" class="col-xs-12 col-sm-9 col-md-8 main-content">
 // HTML-GLOBAL-INDEX: <h1>Global Namespace</h1>
 // HTML-GLOBAL-INDEX: <h2 id="Namespaces">Namespaces</h2>
+// HTML-GLOBAL-INDEX: <li>@nonymous_namespace</li>
 // HTML-GLOBAL-INDEX: <li>PrimaryNamespace</li>
 // HTML-GLOBAL-INDEX: <li>AnotherNamespace</li>
-// HTML-GLOBAL-INDEX: <li>@nonymous_namespace</li>
 
 // MD-GLOBAL-INDEX: # Global Namespace
 // MD-GLOBAL-INDEX: ## Namespaces
+// MD-GLOBAL-INDEX: * [@nonymous_namespace](..{{[\/]}}@nonymous_namespace{{[\/]}}index.md)
 // MD-GLOBAL-INDEX: * [PrimaryNamespace](..{{[\/]}}PrimaryNamespace{{[\/]}}index.md)
 // MD-GLOBAL-INDEX: * [AnotherNamespace](..{{[\/]}}AnotherNamespace{{[\/]}}index.md)
-// MD-GLOBAL-INDEX: * [@nonymous_namespace](..{{[\/]}}@nonymous_namespace{{[\/]}}index.md)
 
 // MD-ALL-FILES: # All Files
 // MD-ALL-FILES: ## [@nonymous_namespace](@nonymous_namespace{{[\/]}}index.md)
diff --git a/clang-tools-extra/test/clang-doc/templates.cpp b/clang-tools-extra/test/clang-doc/templates.cpp
index 4d4a25b8d3b82..2e04a77ac9e62 100644
--- a/clang-tools-extra/test/clang-doc/templates.cpp
+++ b/clang-tools-extra/test/clang-doc/templates.cpp
@@ -18,23 +18,6 @@ void ParamPackFunction(T... args);
 // CHECK: ---
 // CHECK-NEXT: USR:             '{{([0-9A-F]{40})}}'
 // CHECK-NEXT: ChildFunctions:
-// CHECK-NEXT:  - USR:             '{{([0-9A-F]{40})}}'
-// CHECK-NEXT:    Name:            'ParamPackFunction'
-// CHECK-NEXT:    Location:
-// CHECK-NEXT:      - LineNumber:      16
-// CHECK-NEXT:        Filename:        '{{.*}}'
-// CHECK-NEXT:    Params:
-// CHECK-NEXT:      - Type:
-// CHECK-NEXT:          Name:            'T...'
-// CHECK-NEXT:          QualName:        'T...'
-// CHECK-NEXT:        Name:            'args'
-// CHECK-NEXT:    ReturnType:
-// CHECK-NEXT:      Type:
-// CHECK-NEXT:        Name:            'void'
-// CHECK-NEXT:        QualName:        'void'
-// CHECK-NEXT:    Template:
-// CHECK-NEXT:      Params:
-// CHECK-NEXT:        - Contents:        'class... T'
 // CHECK-NEXT:   - USR:             '{{([0-9A-F]{40})}}'
 // CHECK-NEXT:     Name:            'function'
 // CHECK-NEXT:     DefLocation:
@@ -73,4 +56,21 @@ void ParamPackFunction(T... args);
 // CHECK-NEXT:         Params:
 // CHECK-NEXT:           - Contents:        'bool'
 // CHECK-NEXT:           - Contents:        '0'
+// CHECK-NEXT:  - USR:             '{{([0-9A-F]{40})}}'
+// CHECK-NEXT:    Name:            'ParamPackFunction'
+// CHECK-NEXT:    Location:
+// CHECK-NEXT:      - LineNumber:      16
+// CHECK-NEXT:        Filename:        '{{.*}}'
+// CHECK-NEXT:    Params:
+// CHECK-NEXT:      - Type:
+// CHECK-NEXT:          Name:            'T...'
+// CHECK-NEXT:          QualName:        'T...'
+// CHECK-NEXT:        Name:            'args'
+// CHECK-NEXT:    ReturnType:
+// CHECK-NEXT:      Type:
+// CHECK-NEXT:        Name:            'void'
+// CHECK-NEXT:        QualName:        'void'
+// CHECK-NEXT:    Template:
+// CHECK-NEXT:      Params:
+// CHECK-NEXT:        - Contents:        'class... T'
 // CHECK-NEXT: ...

>From 2539d74ad3113798d5ebf91dbba28c73bcb92c0d Mon Sep 17 00:00:00 2001
From: PeterChou1 <peter.chou at mail.utoronto.ca>
Date: Thu, 1 Aug 2024 05:58:09 -0400
Subject: [PATCH 05/13] [clang-doc] clang-format

---
 clang-tools-extra/clang-doc/CMakeLists.txt | 43 +++++++++++++++++-----
 clang-tools-extra/clang-doc/Serialize.cpp  |  4 +-
 2 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/clang-tools-extra/clang-doc/CMakeLists.txt b/clang-tools-extra/clang-doc/CMakeLists.txt
index ec6b51f51563f..975ad8e242e49 100644
--- a/clang-tools-extra/clang-doc/CMakeLists.txt
+++ b/clang-tools-extra/clang-doc/CMakeLists.txt
@@ -1,14 +1,37 @@
-set(LLVM_LINK_COMPONENTS support BitstreamReader FrontendOpenMP)
+set(LLVM_LINK_COMPONENTS
+  support
+  BitstreamReader
+  FrontendOpenMP
+  )
 
-    add_clang_library(
-        clangDoc BitcodeReader.cpp BitcodeWriter.cpp ClangDoc.cpp Generators
-            .cpp HTMLGenerator.cpp Mapper.cpp MDGenerator.cpp Representation
-            .cpp Serialize.cpp YAMLGenerator.cpp
+add_clang_library(clangDoc
+  BitcodeReader.cpp
+  BitcodeWriter.cpp
+  ClangDoc.cpp
+  Generators.cpp
+  HTMLGenerator.cpp
+  Mapper.cpp
+  MDGenerator.cpp
+  Representation.cpp
+  Serialize.cpp
+  YAMLGenerator.cpp
 
-                DEPENDS omp_gen ClangDriverOptions)
+  DEPENDS
+  omp_gen
+  ClangDriverOptions
+)
 
-        clang_target_link_libraries(
-            clangDoc PRIVATE clangAnalysis clangAST clangASTMatchers clangBasic
-                clangFrontend clangIndex clangLex clangTooling clangToolingCore)
+clang_target_link_libraries(clangDoc
+  PRIVATE
+  clangAnalysis
+  clangAST
+  clangASTMatchers
+  clangBasic
+  clangFrontend
+  clangIndex
+  clangLex
+  clangTooling
+  clangToolingCore
+  )
 
-            add_subdirectory(tool)
+add_subdirectory(tool)
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp
index a0eeb312024f0..3b074d849e8a9 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -558,7 +558,7 @@ static void populateFunctionInfo(FunctionInfo &I, const FunctionDecl *D,
 static void populateMemberTypeInfo(MemberTypeInfo &I, const FieldDecl *D) {
   assert(D && "Expect non-null FieldDecl in populateMemberTypeInfo");
 
-  ASTContext &Context = D->getASTContext();
+  ASTContext& Context = D->getASTContext();
   // TODO investigate whether we can use ASTContext::getCommentForDecl instead
   // of this logic. See also similar code in Mapper.cpp.
   RawComment *Comment = Context.getRawCommentForDeclNoCache(D);
@@ -566,7 +566,7 @@ static void populateMemberTypeInfo(MemberTypeInfo &I, const FieldDecl *D) {
     return;
 
   Comment->setAttached();
-  if (comments::FullComment *fc = Comment->parse(Context, nullptr, D)) {
+  if (comments::FullComment* fc = Comment->parse(Context, nullptr, D)) {
     I.Description.emplace_back();
     parseFullComment(fc, I.Description.back());
   }

>From 9fdf07ade8229d861f3536cf2cc6230746caaad8 Mon Sep 17 00:00:00 2001
From: PeterChou1 <peter.chou at mail.utoronto.ca>
Date: Thu, 1 Aug 2024 06:07:10 -0400
Subject: [PATCH 06/13] [clang-doc] cleanup

---
 clang-tools-extra/clang-doc/HTMLGenerator.cpp       | 12 ++++++------
 clang-tools-extra/clang-doc/Representation.cpp      |  2 +-
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp   |  2 +-
 clang-tools-extra/test/clang-doc/basic-project.test |  1 -
 clang-tools-extra/test/clang-doc/namespace.cpp      |  2 +-
 5 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index 036e628d6e8fa..5d600e4fd6b75 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -667,8 +667,8 @@ genHTML(const EnumInfo &I, const ClangDocContext &CDCtx) {
     if (!CDCtx.RepositoryUrl)
       Out.emplace_back(writeFileDefinition(*I.DefLoc));
     else
-      Out.emplace_back(
-          writeFileDefinition(*I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
+      Out.emplace_back(writeFileDefinition(
+          *I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
   }
 
   std::string Description;
@@ -716,8 +716,8 @@ genHTML(const FunctionInfo &I, const ClangDocContext &CDCtx,
     if (!CDCtx.RepositoryUrl)
       Out.emplace_back(writeFileDefinition(*I.DefLoc));
     else
-      Out.emplace_back(
-          writeFileDefinition(*I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
+      Out.emplace_back(writeFileDefinition(
+          *I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
   }
 
   std::string Description;
@@ -783,8 +783,8 @@ genHTML(const RecordInfo &I, Index &InfoIndex, const ClangDocContext &CDCtx,
     if (!CDCtx.RepositoryUrl)
       Out.emplace_back(writeFileDefinition(*I.DefLoc));
     else
-      Out.emplace_back(
-          writeFileDefinition(*I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
+      Out.emplace_back(writeFileDefinition(
+          *I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
   }
 
   std::string Description;
diff --git a/clang-tools-extra/clang-doc/Representation.cpp b/clang-tools-extra/clang-doc/Representation.cpp
index 726ad93aeb715..7377a6995335d 100644
--- a/clang-tools-extra/clang-doc/Representation.cpp
+++ b/clang-tools-extra/clang-doc/Representation.cpp
@@ -78,7 +78,6 @@ mergeInfos(std::vector<std::unique_ptr<Info>> &Values) {
 
   switch (Values[0]->IT) {
   case InfoType::IT_namespace:
-    return reduce<NamespaceInfo>(Values);
   case InfoType::IT_record:
     return reduce<RecordInfo>(Values);
   case InfoType::IT_enum:
@@ -223,6 +222,7 @@ void SymbolInfo::merge(SymbolInfo &&Other) {
 NamespaceInfo::NamespaceInfo(SymbolID USR, StringRef Name, StringRef Path)
     : Info(InfoType::IT_namespace, USR, Name, Path) {}
 
+
 void NamespaceInfo::merge(NamespaceInfo &&Other) {
   assert(mergeable(Other));
   // Reduce children if necessary.
diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 48179bd3d5238..3bb5952a6fea1 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -303,7 +303,7 @@ Example usage for a project using a compile commands database:
         auto R = USRToBitcode.try_emplace(Key, std::vector<StringRef>());
         R.first->second.emplace_back(Value);
       });
-  
+
   // Collects all Infos according to their unique USR value. This map is added
   // to from the thread pool below and is protected by the USRToInfoMutex.
   llvm::sys::Mutex USRToInfoMutex;
diff --git a/clang-tools-extra/test/clang-doc/basic-project.test b/clang-tools-extra/test/clang-doc/basic-project.test
index 2d8e3be4bd504..51d3ac6ce6dcd 100644
--- a/clang-tools-extra/test/clang-doc/basic-project.test
+++ b/clang-tools-extra/test/clang-doc/basic-project.test
@@ -124,7 +124,6 @@
 // HTML-CIRCLE: <p>public double perimeter()</p>
 // HTML-CIRCLE: <p>Defined at line 9 of file {{.*}}Circle.cpp</p>
 
-
 // MD-CALC: # class Calculator
 // MD-CALC: *Defined at .{{[\/]}}include{{[\/]}}Calculator.h#8*
 // MD-CALC: **brief** A simple calculator class.
diff --git a/clang-tools-extra/test/clang-doc/namespace.cpp b/clang-tools-extra/test/clang-doc/namespace.cpp
index 72ed277a2c1e9..12f3cb8a84bc6 100644
--- a/clang-tools-extra/test/clang-doc/namespace.cpp
+++ b/clang-tools-extra/test/clang-doc/namespace.cpp
@@ -290,4 +290,4 @@ namespace AnotherNamespace {
 // MD-INDEX: #  C/C++ Reference
 // MD-INDEX: * Namespace: [@nonymous_namespace](@nonymous_namespace)
 // MD-INDEX: * Namespace: [AnotherNamespace](AnotherNamespace)
-// MD-INDEX: * Namespace: [PrimaryNamespace](PrimaryNamespace)
+// MD-INDEX: * Namespace: [PrimaryNamespace](PrimaryNamespace)
\ No newline at end of file

>From 6d981a30ec5831a9488eed643f2371558e16ab27 Mon Sep 17 00:00:00 2001
From: PeterChou1 <peter.chou at mail.utoronto.ca>
Date: Thu, 1 Aug 2024 06:10:07 -0400
Subject: [PATCH 07/13] [clang-doc] cleanup

---
 clang-tools-extra/clang-doc/Representation.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clang-doc/Representation.cpp b/clang-tools-extra/clang-doc/Representation.cpp
index 7377a6995335d..6ed18e8a91f5c 100644
--- a/clang-tools-extra/clang-doc/Representation.cpp
+++ b/clang-tools-extra/clang-doc/Representation.cpp
@@ -78,6 +78,7 @@ mergeInfos(std::vector<std::unique_ptr<Info>> &Values) {
 
   switch (Values[0]->IT) {
   case InfoType::IT_namespace:
+    return reduce<NamespaceInfo>(Values);
   case InfoType::IT_record:
     return reduce<RecordInfo>(Values);
   case InfoType::IT_enum:
@@ -220,8 +221,7 @@ void SymbolInfo::merge(SymbolInfo &&Other) {
 }
 
 NamespaceInfo::NamespaceInfo(SymbolID USR, StringRef Name, StringRef Path)
-    : Info(InfoType::IT_namespace, USR, Name, Path) {}
-
+      : Info(InfoType::IT_namespace, USR, Name, Path) {}
 
 void NamespaceInfo::merge(NamespaceInfo &&Other) {
   assert(mergeable(Other));

>From c301f1b7f3e395781e34889f95ca4a4681e64915 Mon Sep 17 00:00:00 2001
From: PeterChou1 <peter.chou at mail.utoronto.ca>
Date: Thu, 1 Aug 2024 06:11:17 -0400
Subject: [PATCH 08/13] [clang-doc] cleanup

---
 clang-tools-extra/clang-doc/HTMLGenerator.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index 5d600e4fd6b75..aef22453035c3 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -619,7 +619,7 @@ static std::unique_ptr<HTMLNode> genHTML(const CommentInfo &I) {
     }
     return std::move(FullComment);
   }
-
+ 
   if (I.Kind == "ParagraphComment") {
     auto ParagraphComment = std::make_unique<TagNode>(HTMLTag::TAG_P);
     for (const auto &Child : I.Children) {

>From c26ce3c731dfb13a54718598160b390ec86bb087 Mon Sep 17 00:00:00 2001
From: PeterChou1 <peter.chou at mail.utoronto.ca>
Date: Thu, 1 Aug 2024 06:17:26 -0400
Subject: [PATCH 09/13] [clang-doc] format

---
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 3bb5952a6fea1..38ea4d3cc9825 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -215,8 +215,8 @@ void sortUsrToInfo(llvm::StringMap<std::unique_ptr<doc::Info>>& USRToInfo) {
       Namespace->Children.sort();
     }
     if (Info->IT == doc::InfoType::IT_record) {
-        auto *Record = static_cast<clang::doc::RecordInfo *>(Info.get());
-        Record->Children.sort();
+      auto *Record = static_cast<clang::doc::RecordInfo *>(Info.get());
+      Record->Children.sort();
     }
   }
 }

>From 9f88c79592378e5aca71eca8921659e5ef30fd3e Mon Sep 17 00:00:00 2001
From: PeterChou1 <peter.chou at mail.utoronto.ca>
Date: Thu, 1 Aug 2024 06:30:39 -0400
Subject: [PATCH 10/13] [clang-doc] modify compare function

---
 clang-tools-extra/clang-doc/Representation.h        | 10 +++++++---
 clang-tools-extra/test/clang-doc/basic-project.test |  6 +++---
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/clang-tools-extra/clang-doc/Representation.h b/clang-tools-extra/clang-doc/Representation.h
index 058687572f481..7ced1f7f4db71 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -321,9 +321,13 @@ struct SymbolInfo : public Info {
   llvm::SmallVector<Location, 2> Loc; // Locations where this decl is declared.
 
   bool operator<(const SymbolInfo &Other) const {
-    assert(Loc.size() > 0 && Other.Loc.size() > 0 &&
-           "SymbolInfo must have at least one location");
-    return Loc[0] < Other.Loc[0];
+    if (DefLoc && Other.DefLoc) {
+      return *DefLoc < *Other.DefLoc;
+    }
+    if (Loc.size() > 0 && Other.Loc.size() > 0) {
+      return Loc[0] < Other.Loc[0];
+    }
+    return llvm::toStringRef(USR) < llvm::toStringRef(Other.USR);
   }
 };
 
diff --git a/clang-tools-extra/test/clang-doc/basic-project.test b/clang-tools-extra/test/clang-doc/basic-project.test
index 51d3ac6ce6dcd..c2c7548f5a969 100644
--- a/clang-tools-extra/test/clang-doc/basic-project.test
+++ b/clang-tools-extra/test/clang-doc/basic-project.test
@@ -58,13 +58,13 @@
 // HTML-SHAPE: <p>Defined at line 8 of file {{.*}}Shape.h</p>
 // HTML-SHAPE: <p> Provides a common interface for different types of shapes.</p>
 // HTML-SHAPE: <h2 id="Functions">Functions</h2>
-// HTML-SHAPE: <h3 id="{{([0-9A-F]{40})}}">~Shape</h3>
-// HTML-SHAPE: <p>public void ~Shape()</p>
-// HTML-SHAPE: <p>Defined at line 13 of file {{.*}}Shape.h</p>
 // HTML-SHAPE: <h3 id="{{([0-9A-F]{40})}}">area</h3>
 // HTML-SHAPE: <p>public double area()</p>
 // HTML-SHAPE: <h3 id="{{([0-9A-F]{40})}}">perimeter</h3>
 // HTML-SHAPE: <p>public double perimeter()</p>
+// HTML-SHAPE: <h3 id="{{([0-9A-F]{40})}}">~Shape</h3>
+// HTML-SHAPE: <p>public void ~Shape()</p>
+// HTML-SHAPE: <p>Defined at line 13 of file {{.*}}Shape.h</p>
 
 // HTML-CALC:  <h1>class Calculator</h1>
 // HTML-CALC:  <p>Defined at line 8 of file {{.*}}Calculator.h</p>

>From 92d874b25e693a559c3e6481a0f7d41ff66b8a29 Mon Sep 17 00:00:00 2001
From: PeterChou1 <peter.chou at mail.utoronto.ca>
Date: Thu, 1 Aug 2024 06:35:35 -0400
Subject: [PATCH 11/13] [clang-doc] format

---
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 38ea4d3cc9825..04773fb8a6e72 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -207,7 +207,7 @@ llvm::Error getHtmlAssetFiles(const char *Argv0,
 
 /// Make the output of clang-doc deterministic by sorting the children of
 /// namespaces and records.
-void sortUsrToInfo(llvm::StringMap<std::unique_ptr<doc::Info>>& USRToInfo) {
+void sortUsrToInfo(llvm::StringMap<std::unique_ptr<doc::Info>> &USRToInfo) {
   for (auto &I : USRToInfo) {
     auto &Info = I.second;
     if (Info->IT == doc::InfoType::IT_namespace) {

>From fc2a139f85f8c763a2a178f5b92bb3787683b232 Mon Sep 17 00:00:00 2001
From: PeterChou1 <peter.chou at mail.utoronto.ca>
Date: Thu, 1 Aug 2024 15:46:36 -0400
Subject: [PATCH 12/13] [clang-doc] clang-format

---
 clang-tools-extra/clang-doc/Representation.cpp | 10 +++++-----
 clang-tools-extra/clang-doc/Representation.h   |  6 ++----
 clang-tools-extra/test/clang-doc/namespace.cpp |  6 ++++--
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/clang-tools-extra/clang-doc/Representation.cpp b/clang-tools-extra/clang-doc/Representation.cpp
index 6ed18e8a91f5c..6f140910b321f 100644
--- a/clang-tools-extra/clang-doc/Representation.cpp
+++ b/clang-tools-extra/clang-doc/Representation.cpp
@@ -385,11 +385,11 @@ ClangDocContext::ClangDocContext(tooling::ExecutionContext *ECtx,
 }
 
 void ScopeChildren::sort() {
-  std::sort(Namespaces.begin(), Namespaces.end());
-  std::sort(Records.begin(), Records.end());
-  std::sort(Functions.begin(), Functions.end());
-  std::sort(Enums.begin(), Enums.end());
-  std::sort(Typedefs.begin(), Typedefs.end());
+  llvm::sort(Namespaces.begin(), Namespaces.end());
+  llvm::sort(Records.begin(), Records.end());
+  llvm::sort(Functions.begin(), Functions.end());
+  llvm::sort(Enums.begin(), Enums.end());
+  llvm::sort(Typedefs.begin(), Typedefs.end());
 }
 } // namespace doc
 } // namespace clang
diff --git a/clang-tools-extra/clang-doc/Representation.h b/clang-tools-extra/clang-doc/Representation.h
index 7ced1f7f4db71..5438b767b3e05 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -104,9 +104,7 @@ struct Reference {
 
   bool mergeable(const Reference &Other);
   void merge(Reference &&I);
-  bool operator<(const Reference &Other) const {
-    return llvm::toStringRef(USR) < llvm::toStringRef(Other.USR);
-  }
+  bool operator<(const Reference &Other) const { return Name < Other.Name; }
 
   /// Returns the path for this Reference relative to CurrentPath.
   llvm::SmallString<64> getRelativeFilePath(const StringRef &CurrentPath) const;
@@ -327,7 +325,7 @@ struct SymbolInfo : public Info {
     if (Loc.size() > 0 && Other.Loc.size() > 0) {
       return Loc[0] < Other.Loc[0];
     }
-    return llvm::toStringRef(USR) < llvm::toStringRef(Other.USR);
+    return extractName() < Other.extractName();
   }
 };
 
diff --git a/clang-tools-extra/test/clang-doc/namespace.cpp b/clang-tools-extra/test/clang-doc/namespace.cpp
index 12f3cb8a84bc6..db947985a2ba6 100644
--- a/clang-tools-extra/test/clang-doc/namespace.cpp
+++ b/clang-tools-extra/test/clang-doc/namespace.cpp
@@ -272,14 +272,16 @@ namespace AnotherNamespace {
 // HTML-GLOBAL-INDEX: <h1>Global Namespace</h1>
 // HTML-GLOBAL-INDEX: <h2 id="Namespaces">Namespaces</h2>
 // HTML-GLOBAL-INDEX: <li>@nonymous_namespace</li>
-// HTML-GLOBAL-INDEX: <li>PrimaryNamespace</li>
 // HTML-GLOBAL-INDEX: <li>AnotherNamespace</li>
+// HTML-GLOBAL-INDEX: <li>PrimaryNamespace</li>
+
 
 // MD-GLOBAL-INDEX: # Global Namespace
 // MD-GLOBAL-INDEX: ## Namespaces
 // MD-GLOBAL-INDEX: * [@nonymous_namespace](..{{[\/]}}@nonymous_namespace{{[\/]}}index.md)
-// MD-GLOBAL-INDEX: * [PrimaryNamespace](..{{[\/]}}PrimaryNamespace{{[\/]}}index.md)
 // MD-GLOBAL-INDEX: * [AnotherNamespace](..{{[\/]}}AnotherNamespace{{[\/]}}index.md)
+// MD-GLOBAL-INDEX: * [PrimaryNamespace](..{{[\/]}}PrimaryNamespace{{[\/]}}index.md)
+
 
 // MD-ALL-FILES: # All Files
 // MD-ALL-FILES: ## [@nonymous_namespace](@nonymous_namespace{{[\/]}}index.md)

>From 49b39e69d381bcfefff712995e85683b52c4709c Mon Sep 17 00:00:00 2001
From: PeterChou1 <peter.chou at mail.utoronto.ca>
Date: Thu, 1 Aug 2024 16:04:27 -0400
Subject: [PATCH 13/13] [clang-doc] fix test

---
 .../test/clang-doc/templates.cpp              | 34 +++++++++----------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/clang-tools-extra/test/clang-doc/templates.cpp b/clang-tools-extra/test/clang-doc/templates.cpp
index 2e04a77ac9e62..4d4a25b8d3b82 100644
--- a/clang-tools-extra/test/clang-doc/templates.cpp
+++ b/clang-tools-extra/test/clang-doc/templates.cpp
@@ -18,6 +18,23 @@ void ParamPackFunction(T... args);
 // CHECK: ---
 // CHECK-NEXT: USR:             '{{([0-9A-F]{40})}}'
 // CHECK-NEXT: ChildFunctions:
+// CHECK-NEXT:  - USR:             '{{([0-9A-F]{40})}}'
+// CHECK-NEXT:    Name:            'ParamPackFunction'
+// CHECK-NEXT:    Location:
+// CHECK-NEXT:      - LineNumber:      16
+// CHECK-NEXT:        Filename:        '{{.*}}'
+// CHECK-NEXT:    Params:
+// CHECK-NEXT:      - Type:
+// CHECK-NEXT:          Name:            'T...'
+// CHECK-NEXT:          QualName:        'T...'
+// CHECK-NEXT:        Name:            'args'
+// CHECK-NEXT:    ReturnType:
+// CHECK-NEXT:      Type:
+// CHECK-NEXT:        Name:            'void'
+// CHECK-NEXT:        QualName:        'void'
+// CHECK-NEXT:    Template:
+// CHECK-NEXT:      Params:
+// CHECK-NEXT:        - Contents:        'class... T'
 // CHECK-NEXT:   - USR:             '{{([0-9A-F]{40})}}'
 // CHECK-NEXT:     Name:            'function'
 // CHECK-NEXT:     DefLocation:
@@ -56,21 +73,4 @@ void ParamPackFunction(T... args);
 // CHECK-NEXT:         Params:
 // CHECK-NEXT:           - Contents:        'bool'
 // CHECK-NEXT:           - Contents:        '0'
-// CHECK-NEXT:  - USR:             '{{([0-9A-F]{40})}}'
-// CHECK-NEXT:    Name:            'ParamPackFunction'
-// CHECK-NEXT:    Location:
-// CHECK-NEXT:      - LineNumber:      16
-// CHECK-NEXT:        Filename:        '{{.*}}'
-// CHECK-NEXT:    Params:
-// CHECK-NEXT:      - Type:
-// CHECK-NEXT:          Name:            'T...'
-// CHECK-NEXT:          QualName:        'T...'
-// CHECK-NEXT:        Name:            'args'
-// CHECK-NEXT:    ReturnType:
-// CHECK-NEXT:      Type:
-// CHECK-NEXT:        Name:            'void'
-// CHECK-NEXT:        QualName:        'void'
-// CHECK-NEXT:    Template:
-// CHECK-NEXT:      Params:
-// CHECK-NEXT:        - Contents:        'class... T'
 // CHECK-NEXT: ...



More information about the cfe-commits mailing list