[clang] [clang] Avoid printing overly large integer/_BitInt numbers in static assertion failure diagnostics #71675 (PR #145053)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 1 06:24:35 PDT 2025
================
@@ -17575,7 +17576,21 @@ static bool ConvertAPValueToString(const APValue &V, QualType T,
break;
}
}
- V.getInt().toString(Str);
+
+ llvm::APSInt vInt = V.getInt();
+ if (llvm::APSInt::compareValues(
+ vInt, llvm::APSInt::getUnsigned(
+ std::numeric_limits<uint64_t>::max())) >= 0 ||
+ vInt < std::numeric_limits<int64_t>::min()) {
+ // The value of cutSize is not special, it is just a number of
+ // characters that gives us enough info without losing readability
+ const int cutSize = 20;
+ vInt.toString(Str, 16);
+ Str.erase(Str.begin() + cutSize, Str.end() - cutSize);
----------------
erichkeane wrote:
>we can get the number of remaing using value.logBase2/log2(Radix) +1 that actually gives the exact count.
That sounds VAGUELY familiar :) Its been a few decades since I've been in a math class....
With the 'pow', you probably need SOME sort of guard to make sure you don't exceed the number we can store.
https://github.com/llvm/llvm-project/pull/145053
More information about the cfe-commits
mailing list