[compiler-rt] [scudo] Clean up string handling (PR #86364)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 22 17:06:57 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff c3747883a0bf34d271bc89dbfc60590adf75d999 6615b7236d20bfb51d36bbc74e2ad1fe29416e2e -- compiler-rt/lib/scudo/standalone/fuchsia.cpp compiler-rt/lib/scudo/standalone/mem_map_fuchsia.cpp compiler-rt/lib/scudo/standalone/report_linux.cpp compiler-rt/lib/scudo/standalone/string_utils.cpp compiler-rt/lib/scudo/standalone/string_utils.h compiler-rt/lib/scudo/standalone/tests/strings_test.cpp compiler-rt/lib/scudo/standalone/tests/vector_test.cpp compiler-rt/lib/scudo/standalone/vector.h
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/compiler-rt/lib/scudo/standalone/report_linux.cpp b/compiler-rt/lib/scudo/standalone/report_linux.cpp
index 4e28861c3b..dfddef3324 100644
--- a/compiler-rt/lib/scudo/standalone/report_linux.cpp
+++ b/compiler-rt/lib/scudo/standalone/report_linux.cpp
@@ -43,7 +43,8 @@ void NORETURN reportUnmapError(uptr Addr, uptr Size) {
void NORETURN reportProtectError(uptr Addr, uptr Size, int Prot) {
ScopedString Error;
- Error.append("Scudo ERROR: internal protect failure (error desc=%s) Addr 0x%zx "
+ Error.append(
+ "Scudo ERROR: internal protect failure (error desc=%s) Addr 0x%zx "
"Size %zu Prot %x\n",
strerror(errno), Addr, Size, Prot);
reportRawError(Error.data());
diff --git a/compiler-rt/lib/scudo/standalone/string_utils.cpp b/compiler-rt/lib/scudo/standalone/string_utils.cpp
index 3d8121275d..c925fb7028 100644
--- a/compiler-rt/lib/scudo/standalone/string_utils.cpp
+++ b/compiler-rt/lib/scudo/standalone/string_utils.cpp
@@ -17,9 +17,8 @@ namespace scudo {
// Appends number in a given Base to buffer. If its length is less than
// |MinNumberLength|, it is padded with leading zeroes or spaces, depending
// on the value of |PadWithZero|.
-void ScopedString::appendNumber(u64 AbsoluteValue,
- u8 Base, u8 MinNumberLength, bool PadWithZero,
- bool Negative, bool Upper) {
+void ScopedString::appendNumber(u64 AbsoluteValue, u8 Base, u8 MinNumberLength,
+ bool PadWithZero, bool Negative, bool Upper) {
constexpr uptr MaxLen = 30;
RAW_CHECK(Base == 10 || Base == 16);
RAW_CHECK(Base == 10 || !Negative);
@@ -59,21 +58,20 @@ void ScopedString::appendNumber(u64 AbsoluteValue,
}
}
-void ScopedString::appendUnsigned(u64 Num,
- u8 Base, u8 MinNumberLength, bool PadWithZero,
- bool Upper) {
- appendNumber(Num, Base, MinNumberLength,
- PadWithZero, /*Negative=*/false, Upper);
+void ScopedString::appendUnsigned(u64 Num, u8 Base, u8 MinNumberLength,
+ bool PadWithZero, bool Upper) {
+ appendNumber(Num, Base, MinNumberLength, PadWithZero, /*Negative=*/false,
+ Upper);
}
-void ScopedString::appendSignedDecimal(s64 Num,
- u8 MinNumberLength, bool PadWithZero) {
+void ScopedString::appendSignedDecimal(s64 Num, u8 MinNumberLength,
+ bool PadWithZero) {
const bool Negative = (Num < 0);
const u64 UnsignedNum = (Num == INT64_MIN)
? static_cast<u64>(INT64_MAX) + 1
: static_cast<u64>(Negative ? -Num : Num);
- appendNumber(UnsignedNum, 10, MinNumberLength,
- PadWithZero, Negative, /*Upper=*/false);
+ appendNumber(UnsignedNum, 10, MinNumberLength, PadWithZero, Negative,
+ /*Upper=*/false);
}
#include <stdio.h>
@@ -103,8 +101,8 @@ void ScopedString::appendString(int Width, int MaxChars, const char *S) {
void ScopedString::appendPointer(u64 ptr_value) {
appendString(0, -1, "0x");
- appendUnsigned(ptr_value, 16,
- SCUDO_POINTER_FORMAT_LENGTH, /*PadWithZero=*/true,
+ appendUnsigned(ptr_value, 16, SCUDO_POINTER_FORMAT_LENGTH,
+ /*PadWithZero=*/true,
/*Upper=*/false);
}
@@ -166,8 +164,7 @@ void ScopedString::vappend(const char *Format, va_list &Args) {
: HaveZ ? va_arg(Args, uptr)
: va_arg(Args, unsigned);
const bool Upper = (*Cur == 'X');
- appendUnsigned(UVal, (*Cur == 'u') ? 10 : 16,
- Width, PadWithZero, Upper);
+ appendUnsigned(UVal, (*Cur == 'u') ? 10 : 16, Width, PadWithZero, Upper);
break;
}
case 'p': {
@@ -179,7 +176,8 @@ void ScopedString::vappend(const char *Format, va_list &Args) {
RAW_CHECK_MSG(!HaveLength, PrintfFormatsHelp);
// Only left-justified Width is supported.
CHECK(!HaveWidth || LeftJustified);
- appendString(LeftJustified ? -Width : Width, Precision, va_arg(Args, char *));
+ appendString(LeftJustified ? -Width : Width, Precision,
+ va_arg(Args, char *));
break;
}
case 'c': {
diff --git a/compiler-rt/lib/scudo/standalone/string_utils.h b/compiler-rt/lib/scudo/standalone/string_utils.h
index d5405bb8d1..6e00b63779 100644
--- a/compiler-rt/lib/scudo/standalone/string_utils.h
+++ b/compiler-rt/lib/scudo/standalone/string_utils.h
@@ -32,8 +32,10 @@ public:
uptr capacity() { return String.capacity() - 1; }
private:
- void appendNumber(u64 AbsoluteValue, u8 Base, u8 MinNumberLength, bool PadWithZero, bool Negative, bool Upper);
- void appendUnsigned(u64 Num, u8 Base, u8 MinNumberLength, bool PadWithZero, bool Upper);
+ void appendNumber(u64 AbsoluteValue, u8 Base, u8 MinNumberLength,
+ bool PadWithZero, bool Negative, bool Upper);
+ void appendUnsigned(u64 Num, u8 Base, u8 MinNumberLength, bool PadWithZero,
+ bool Upper);
void appendSignedDecimal(s64 Num, u8 MinNumberLength, bool PadWithZero);
void appendString(int Width, int MaxChars, const char *S);
void appendPointer(u64 ptr_value);
diff --git a/compiler-rt/lib/scudo/standalone/tests/strings_test.cpp b/compiler-rt/lib/scudo/standalone/tests/strings_test.cpp
index 7cc107f7b1..e068c48fc9 100644
--- a/compiler-rt/lib/scudo/standalone/tests/strings_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/strings_test.cpp
@@ -136,7 +136,7 @@ TEST(ScudoStringsTest, CapacityIncreaseFails) {
rlimit Limit = {};
EXPECT_EQ(0, getrlimit(RLIMIT_AS, &Limit));
- rlimit EmptyLimit = {.rlim_max=Limit.rlim_max};
+ rlimit EmptyLimit = {.rlim_max = Limit.rlim_max};
EXPECT_EQ(0, setrlimit(RLIMIT_AS, &EmptyLimit));
// Test requires that the default length is at least 6 characters.
diff --git a/compiler-rt/lib/scudo/standalone/tests/vector_test.cpp b/compiler-rt/lib/scudo/standalone/tests/vector_test.cpp
index e16bb8452f..b7678678d8 100644
--- a/compiler-rt/lib/scudo/standalone/tests/vector_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/vector_test.cpp
@@ -55,7 +55,7 @@ TEST(ScudoVectorTest, ReallocateFails) {
rlimit Limit = {};
EXPECT_EQ(0, getrlimit(RLIMIT_AS, &Limit));
- rlimit EmptyLimit = { .rlim_max = Limit.rlim_max};
+ rlimit EmptyLimit = {.rlim_max = Limit.rlim_max};
EXPECT_EQ(0, setrlimit(RLIMIT_AS, &EmptyLimit));
V.resize(capacity);
diff --git a/compiler-rt/lib/scudo/standalone/vector.h b/compiler-rt/lib/scudo/standalone/vector.h
index 255c764713..0b4911b320 100644
--- a/compiler-rt/lib/scudo/standalone/vector.h
+++ b/compiler-rt/lib/scudo/standalone/vector.h
@@ -98,7 +98,8 @@ private:
MemMapT NewExternalBuffer;
NewCapacity = roundUp(NewCapacity * sizeof(T), getPageSizeCached());
- if (!NewExternalBuffer.map(/*Addr=*/0U, NewCapacity, "scudo:vector", MAP_ALLOWNOMEM)) {
+ if (!NewExternalBuffer.map(/*Addr=*/0U, NewCapacity, "scudo:vector",
+ MAP_ALLOWNOMEM)) {
return false;
}
T *NewExternalData = reinterpret_cast<T *>(NewExternalBuffer.getBase());
``````````
</details>
https://github.com/llvm/llvm-project/pull/86364
More information about the llvm-commits
mailing list