[llvm] [InstrProf] Correct buffer size for encodeULEB128 (PR #67011)

Kazushi Marukawa via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 21 06:09:27 PDT 2023


https://github.com/kaz7 created https://github.com/llvm/llvm-project/pull/67011

This function uses 16 bytes buffer to encode two 64 bits data. However, the encoding method requires 10 bytes to encode one 64 bits data, so encoded data actually requiress 20 bytes total.

I send a patch about this at https://bugs.llvm.org/show_bug.cgi?id=37447, but it is left as is.  So I'm submitting the patch again.  I personally recommend to remove encodeULEB128 with buffer version and use only encodeULEB128 with stream version.

>From d96547ccdcb979a1b8c5a2de89084992a7b7303c Mon Sep 17 00:00:00 2001
From: "Kazushi (Jam) Marukawa" <marukawa at nec.com>
Date: Thu, 21 Sep 2023 21:56:34 +0900
Subject: [PATCH] [InstrProf] Correct buffer size for encodeULEB128

This function uses 16 bytes buffer to encode two 64 bits data.
However, the encoding method requires 10 bytes to encode one 64 bits
data, so encoded data actually requiress 20 bytes total.

I send a patch about this at https://bugs.llvm.org/show_bug.cgi?id=37447,
but it is left as is.  So I'm submitting the patch again.  I personally
recommend to remove encodeULEB128 with buffer version and use only
encodeULEB128 with stream version.
---
 llvm/lib/ProfileData/InstrProf.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp
index 7e2ee660978a46c..39dadde2d9339b3 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -501,7 +501,7 @@ Error collectPGOFuncNameStrings(ArrayRef<std::string> NameStrs,
                                 bool doCompression, std::string &Result) {
   assert(!NameStrs.empty() && "No name data to emit");
 
-  uint8_t Header[16], *P = Header;
+  uint8_t Header[20], *P = Header;
   std::string UncompressedNameStrings =
       join(NameStrs.begin(), NameStrs.end(), getInstrProfNameSeparator());
 



More information about the llvm-commits mailing list