[PATCH] D142464: [llvm] Do not zero out write_unsigned_impl internal buffer

serge via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 24 06:08:42 PST 2023


serge-sans-paille created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
serge-sans-paille requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Current implementation uselessly calls memset on its internal buffer
while it does not read the non overwritten part.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142464

Files:
  llvm/lib/Support/NativeFormatting.cpp
  llvm/unittests/Support/NativeFormatTests.cpp


Index: llvm/unittests/Support/NativeFormatTests.cpp
===================================================================
--- llvm/unittests/Support/NativeFormatTests.cpp
+++ llvm/unittests/Support/NativeFormatTests.cpp
@@ -48,6 +48,8 @@
 TEST(NativeFormatTest, BasicIntegerTests) {
   // Simple integers with no decimal.
   EXPECT_EQ("0", format_number(0, IntegerStyle::Integer));
+  EXPECT_EQ("1", format_number(1, IntegerStyle::Integer));
+  EXPECT_EQ("-1", format_number(-1, IntegerStyle::Integer));
   EXPECT_EQ("2425", format_number(2425, IntegerStyle::Integer));
   EXPECT_EQ("-2425", format_number(-2425, IntegerStyle::Integer));
 
Index: llvm/lib/Support/NativeFormatting.cpp
===================================================================
--- llvm/lib/Support/NativeFormatting.cpp
+++ llvm/lib/Support/NativeFormatting.cpp
@@ -58,10 +58,7 @@
   static_assert(std::is_unsigned_v<T>, "Value is not unsigned!");
 
   char NumberBuffer[128];
-  std::memset(NumberBuffer, '0', sizeof(NumberBuffer));
-
-  size_t Len = 0;
-  Len = format_to_buffer(N, NumberBuffer);
+  size_t Len = format_to_buffer(N, NumberBuffer);
 
   if (IsNegative)
     S << '-';


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142464.491740.patch
Type: text/x-patch
Size: 1159 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230124/e5357461/attachment.bin>


More information about the llvm-commits mailing list