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

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 29 04:46:10 PST 2024


================
@@ -2257,17 +2266,27 @@ void APInt::toString(SmallVectorImpl<char> &Str, unsigned Radix, bool Signed,
     unsigned ShiftAmt = (Radix == 16 ? 4 : (Radix == 8 ? 3 : 1));
     unsigned MaskAmt = Radix - 1;
 
+    int Pos = 0;
     while (Tmp.getBoolValue()) {
       unsigned Digit = unsigned(Tmp.getRawData()[0]) & MaskAmt;
+      if (insertSeparators && Pos % Grouping == 0 && Pos > 0) {
+        Str.push_back('\'');
+      }
       Str.push_back(Digits[Digit]);
       Tmp.lshrInPlace(ShiftAmt);
+      Pos++;
     }
   } else {
+    int Pos = 0;
     while (Tmp.getBoolValue()) {
       uint64_t Digit;
       udivrem(Tmp, Radix, Tmp, Digit);
       assert(Digit < Radix && "divide failed");
+      if (insertSeparators && Pos % Grouping == 0 && Pos > 0) {
+        Str.push_back('\'');
+      }
----------------
AaronBallman wrote:

Here too

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


More information about the cfe-commits mailing list