[clang] [llvm] [clang] Use separator for large numeric values in overflow diagnostic (PR #80939)

via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 6 21:47:12 PST 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 adbf21f12b3069b2554efb39f2e92c6cf6f24940 c3efdb00f58ef91e587d37b08d06982a81ccefc4 -- clang/lib/AST/ExprConstant.cpp llvm/include/llvm/ADT/APInt.h llvm/include/llvm/ADT/StringExtras.h llvm/lib/Support/APInt.cpp llvm/unittests/ADT/APIntTest.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h
index 0d696e7a6f..dd6d71b933 100644
--- a/llvm/include/llvm/ADT/APInt.h
+++ b/llvm/include/llvm/ADT/APInt.h
@@ -1626,7 +1626,7 @@ public:
   /// SmallString. If Radix > 10, UpperCase determine the case of letter
   /// digits.
   void toString(SmallVectorImpl<char> &Str, unsigned Radix, bool Signed,
-                bool formatAsCLiteral = false, bool UpperCase = true, 
+                bool formatAsCLiteral = false, bool UpperCase = true,
                 bool insertSeparators = false) const;
 
   /// Considers the APInt to be unsigned and converts it into a string in the
diff --git a/llvm/include/llvm/ADT/StringExtras.h b/llvm/include/llvm/ADT/StringExtras.h
index f96b2032f0..32f5828c92 100644
--- a/llvm/include/llvm/ADT/StringExtras.h
+++ b/llvm/include/llvm/ADT/StringExtras.h
@@ -330,8 +330,7 @@ inline std::string itostr(int64_t X) {
 
 inline std::string toString(const APInt &I, unsigned Radix, bool Signed,
                             bool formatAsCLiteral = false,
-                            bool upperCase = true,
-                            bool addSeparators = false) {
+                            bool upperCase = true, bool addSeparators = false) {
   SmallString<40> S;
   I.toString(S, Radix, Signed, formatAsCLiteral, upperCase, addSeparators);
   return std::string(S);
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index e7ca82a6c1..a186b81bc6 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -2161,7 +2161,7 @@ void APInt::fromString(unsigned numbits, StringRef str, uint8_t radix) {
 }
 
 void APInt::toString(SmallVectorImpl<char> &Str, unsigned Radix, bool Signed,
-                     bool formatAsCLiteral, bool UpperCase, 
+                     bool formatAsCLiteral, bool UpperCase,
                      bool insertSeparators) const {
   assert((Radix == 10 || Radix == 8 || Radix == 16 || Radix == 2 ||
           Radix == 36) &&
@@ -2232,7 +2232,7 @@ void APInt::toString(SmallVectorImpl<char> &Str, unsigned Radix, bool Signed,
 
     int Pos = 0;
     while (N) {
-      if (insertSeparators && Pos%Grouping==0 && Pos > 0) {
+      if (insertSeparators && Pos % Grouping == 0 && Pos > 0) {
         *--BufPtr = '\'';
       }
       *--BufPtr = Digits[N % Radix];
@@ -2272,7 +2272,7 @@ void APInt::toString(SmallVectorImpl<char> &Str, unsigned Radix, bool Signed,
     int Pos = 0;
     while (Tmp.getBoolValue()) {
       unsigned Digit = unsigned(Tmp.getRawData()[0]) & MaskAmt;
-      if (insertSeparators && Pos%Grouping==0 && Pos>0) {
+      if (insertSeparators && Pos % Grouping == 0 && Pos > 0) {
         Str.push_back('\'');
       }
       Str.push_back(Digits[Digit]);
@@ -2285,7 +2285,7 @@ void APInt::toString(SmallVectorImpl<char> &Str, unsigned Radix, bool Signed,
       uint64_t Digit;
       udivrem(Tmp, Radix, Tmp, Digit);
       assert(Digit < Radix && "divide failed");
-      if (insertSeparators && Pos%Grouping==0 && Pos>0) {
+      if (insertSeparators && Pos % Grouping == 0 && Pos > 0) {
         Str.push_back('\'');
       }
       Str.push_back(Digits[Digit]);
diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp
index 843a7c447c..e3e7e1e7ba 100644
--- a/llvm/unittests/ADT/APIntTest.cpp
+++ b/llvm/unittests/ADT/APIntTest.cpp
@@ -1446,10 +1446,10 @@ TEST(APIntTest, toString) {
   APInt(64, -1000000, isSigned).toString(S, 16, isSigned, true, true, true);
   EXPECT_EQ(std::string(S), "-0xF'4240");
   S.clear();
-  APInt(64, -1'000'000'000, isSigned).toString(S, 36, isSigned, false, false, true);
+  APInt(64, -1'000'000'000, isSigned)
+      .toString(S, 36, isSigned, false, false, true);
   EXPECT_EQ(std::string(S), "-gj'dgxs");
   S.clear();
-
 }
 
 TEST(APIntTest, Log2) {

``````````

</details>


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


More information about the llvm-commits mailing list