[clang] [clang] Avoid printing overly large integer/_BitInt numbers in static assertion failure diagnostics #71675 (PR #145053)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 30 05:02:59 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);
----------------
tbaederr wrote:
I don't really know how this is supposed to work. We need to know what to display _without_ printing the value to a string at all, because THAT is what's breaking our neck. The simplest solution would be to just check the value (or even `getActiveBits()`?) and if that is larger than some arbitrary value (you can just check that printing the note doesn't take longer than, say, 3 seconds), we simply skip the note altogether.
https://github.com/llvm/llvm-project/pull/145053
More information about the cfe-commits
mailing list