Author: Erick Velez
Date: 2025-08-27T08:01:46-07:00
New Revision: 5136ef93df170c1facffa335cb788e7af40e0bd4

URL: 
https://github.com/llvm/llvm-project/commit/5136ef93df170c1facffa335cb788e7af40e0bd4
DIFF: 
https://github.com/llvm/llvm-project/commit/5136ef93df170c1facffa335cb788e7af40e0bd4.diff

LOG: [clang-doc] lower filename length limit by 5 (#155511)

The previous limit did not take into account filename extensions. Since
the extensions we use (.yaml, .json, .html, .md) are at most 5
characters, we can lower the limit by 5.

Also add some tests to make sure the rules are observed and don't
explicitly crash clang-doc.

Added: 
    clang-tools-extra/test/clang-doc/long-name.cpp

Modified: 
    clang-tools-extra/clang-doc/Serialize.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-doc/Serialize.cpp 
b/clang-tools-extra/clang-doc/Serialize.cpp
index 506cc0a3b0e8f..dd7cd0b2ae736 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -778,7 +778,9 @@ static void populateSymbolInfo(SymbolInfo &I, const T *D, 
const FullComment *C,
     Mangler->mangleCXXVTable(CXXD, MangledStream);
   else
     MangledStream << D->getNameAsString();
-  if (MangledName.size() > 255)
+  // A 250 length limit was chosen since 255 is a common limit across
+  // 
diff erent filesystems, with a 5 character buffer for file extensions.
+  if (MangledName.size() > 250)
     // File creation fails if the mangled name is too long, so default to the
     // USR. We should look for a better check since filesystems 
diff er in
     // maximum filename length

diff  --git a/clang-tools-extra/test/clang-doc/long-name.cpp 
b/clang-tools-extra/test/clang-doc/long-name.cpp
new file mode 100644
index 0000000000000..b33337588da19
--- /dev/null
+++ b/clang-tools-extra/test/clang-doc/long-name.cpp
@@ -0,0 +1,14 @@
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: clang-doc --output=%t --format=mustache --executor=standalone %s
+// RUN: ls %t/json | FileCheck %s -check-prefix=CHECK-JSON
+// RUN: ls %t/html | FileCheck %s -check-prefix=CHECK-HTML
+
+struct 
ThisStructHasANameThatResultsInAMangledNameThatIsExactly250CharactersLongThatIsSupposedToTestTheFilenameLengthLimitsWithinClangDocInOrdertoSeeifclangdocwillcrashornotdependingonthelengthofthestructIfTheLengthIsTooLongThenClangDocWillCrashAnd12
 {};
+
+// This name is 1 character over the limit, so it will be serialized as a USR.
+struct 
ThisStructHasANameThatResultsInAMangledNameThatIsExactly251CharactersLongThatIsSupposedToTestTheFilenameLengthLimitsWithinClangDocInOrdertoSeeifclangdocwillcrashornotdependingonthelengthofthestructIfTheLengthIsTooLongThenClangDocWillCrashAnd123
 {};
+
+// CHECK-JSON: 
ThisStructHasANameThatResultsInAMangledNameThatIsExactly250CharactersLongThatIsSupposedToTestTheFilenameLengthLimitsWithinClangDocInOrdertoSeeifclangdocwillcrashornotdependingonthelengthofthestructIfTheLengthIsTooLongThenClangDocWillCrashAnd12.json
+// CHECK-JSON: {{[0-9A-F]*}}.json
+// CHECK-HTML: 
ThisStructHasANameThatResultsInAMangledNameThatIsExactly250CharactersLongThatIsSupposedToTestTheFilenameLengthLimitsWithinClangDocInOrdertoSeeifclangdocwillcrashornotdependingonthelengthofthestructIfTheLengthIsTooLongThenClangDocWillCrashAnd12.html
+// CHECK-HTML: {{[0-9A-F]*}}.html


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to