[llvm] [SampleFDO] Extend the function base name max size (PR #135863)

via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 15 14:44:32 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Lei Wang (wlei-llvm)

<details>
<summary>Changes</summary>

The function base name could be way long which leads to a crash. Update to extend the max size.

Also changed to use dynamic allocation( `std::vector<char>` ) to avoid stack overflow.

---
Full diff: https://github.com/llvm/llvm-project/pull/135863.diff


1 Files Affected:

- (modified) llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp (+3-3) 


``````````diff
diff --git a/llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp b/llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp
index d6d1b7c51d4c0..963c321772d6e 100644
--- a/llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp
@@ -737,11 +737,11 @@ bool SampleProfileMatcher::functionMatchesProfileHelper(
     auto FunctionName = FName.str();
     if (Demangler.partialDemangle(FunctionName.c_str()))
       return std::string();
-    constexpr size_t MaxBaseNameSize = 4096;
-    char BaseNameBuf[MaxBaseNameSize] = {};
+    constexpr size_t MaxBaseNameSize = 65536;
+    std::vector<char> BaseNameBuf(MaxBaseNameSize, 0);
     size_t BaseNameSize = MaxBaseNameSize;
     char *BaseNamePtr =
-        Demangler.getFunctionBaseName(BaseNameBuf, &BaseNameSize);
+        Demangler.getFunctionBaseName(BaseNameBuf.data(), &BaseNameSize);
     return (BaseNamePtr && BaseNameSize)
                ? std::string(BaseNamePtr, BaseNameSize)
                : std::string();

``````````

</details>


https://github.com/llvm/llvm-project/pull/135863


More information about the llvm-commits mailing list