Skip to content

Commit e80a207

Browse files
authored
[clang-doc] concatenate SymbolIDs to truncated mangled names (llvm#159490)
Previously, if mangled names were too long to be used as filenames, the object's SymbolID was used as a filename. This worked for length restrictions, but made URLs/filenames inconsistent. This patch truncates the mangled name and appends the SymbolID. Thus, we can keep some context in the URL/filename while preserving uniqueness.
1 parent d3c8e18 commit e80a207

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -780,12 +780,10 @@ static void populateSymbolInfo(SymbolInfo &I, const T *D, const FullComment *C,
780780
MangledStream << D->getNameAsString();
781781
// A 250 length limit was chosen since 255 is a common limit across
782782
// different filesystems, with a 5 character buffer for file extensions.
783-
if (MangledName.size() > 250)
784-
// File creation fails if the mangled name is too long, so default to the
785-
// USR. We should look for a better check since filesystems differ in
786-
// maximum filename length
787-
I.MangledName = llvm::toStringRef(llvm::toHex(I.USR));
788-
else
783+
if (MangledName.size() > 250) {
784+
auto SymbolID = llvm::toStringRef(llvm::toHex(I.USR)).str();
785+
I.MangledName = MangledName.substr(0, 250 - SymbolID.size()) + SymbolID;
786+
} else
789787
I.MangledName = MangledName;
790788
delete Mangler;
791789
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ struct ThisStructHasANameThatResultsInAMangledNameThatIsExactly250CharactersLong
99
struct ThisStructHasANameThatResultsInAMangledNameThatIsExactly251CharactersLongThatIsSupposedToTestTheFilenameLengthLimitsWithinClangDocInOrdertoSeeifclangdocwillcrashornotdependingonthelengthofthestructIfTheLengthIsTooLongThenClangDocWillCrashAnd123 {};
1010

1111
// CHECK-JSON: ThisStructHasANameThatResultsInAMangledNameThatIsExactly250CharactersLongThatIsSupposedToTestTheFilenameLengthLimitsWithinClangDocInOrdertoSeeifclangdocwillcrashornotdependingonthelengthofthestructIfTheLengthIsTooLongThenClangDocWillCrashAnd12.json
12-
// CHECK-JSON: {{[0-9A-F]*}}.json
12+
// CHECK-JSON: _ZTV244ThisStructHasANameThatResultsInAMangledNameThatIsExactly251CharactersLongThatIsSupposedToTestTheFilenameLengthLimitsWithinClangDocInOrdertoSeeifclangdocwillcrashornotdependingonthelengthofthestructIfTheL29DE8558215A13A506661C0E01E50AA3E5C9C7FA.json
1313
// CHECK-HTML: ThisStructHasANameThatResultsInAMangledNameThatIsExactly250CharactersLongThatIsSupposedToTestTheFilenameLengthLimitsWithinClangDocInOrdertoSeeifclangdocwillcrashornotdependingonthelengthofthestructIfTheLengthIsTooLongThenClangDocWillCrashAnd12.html
14-
// CHECK-HTML: {{[0-9A-F]*}}.html
14+
// CHECK-HTML: _ZTV244ThisStructHasANameThatResultsInAMangledNameThatIsExactly251CharactersLongThatIsSupposedToTestTheFilenameLengthLimitsWithinClangDocInOrdertoSeeifclangdocwillcrashornotdependingonthelengthofthestructIfTheL29DE8558215A13A506661C0E01E50AA3E5C9C7FA.html

0 commit comments

Comments
 (0)