From 8f79b0fe0047d6a3857ab2dd4bd121a1c4e3afba Mon Sep 17 00:00:00 2001 From: serge-sans-paille Date: Tue, 24 Jan 2023 14:52:43 +0100 Subject: [PATCH] [llvm] Do not zero out write_unsigned_impl internal buffer Current implementation uselessly calls memset on its internal buffer while it does not read the non overwritten part. Differential Revision: https://reviews.llvm.org/D142464 --- llvm/lib/Support/NativeFormatting.cpp | 5 +---- llvm/unittests/Support/NativeFormatTests.cpp | 2 ++ 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Support/NativeFormatting.cpp b/llvm/lib/Support/NativeFormatting.cpp index 6e8137c405b8..3b9273e1eaad 100644 --- a/llvm/lib/Support/NativeFormatting.cpp +++ b/llvm/lib/Support/NativeFormatting.cpp @@ -58,10 +58,7 @@ static void write_unsigned_impl(raw_ostream &S, T N, size_t MinDigits, static_assert(std::is_unsigned_v, "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 << '-'; diff --git a/llvm/unittests/Support/NativeFormatTests.cpp b/llvm/unittests/Support/NativeFormatTests.cpp index 197fad1f83cf..5568727bcc90 100644 --- a/llvm/unittests/Support/NativeFormatTests.cpp +++ b/llvm/unittests/Support/NativeFormatTests.cpp @@ -48,6 +48,8 @@ std::string format_number(double D, FloatStyle Style, 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)); -- 2.34.1