[clang] [Clang] Add thousands-separator to "cannot allocate array; evaluated array bound [...] exceeds the limit" diagnostic (PR #211785)
Ambrose Leeb via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 2 09:57:03 PDT 2026
================
@@ -1429,19 +1429,33 @@ inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
return DB;
}
+inline constexpr uint64_t DiagnosticIntegerSeparatorThreshold = 100'000;
+
+inline std::string formatDiagnosticInteger(const llvm::APInt &Val,
+ bool Signed) {
+ bool Small = false;
+ if (Signed) {
+ if (Val.getSignificantBits() <= 64) {
+ int64_t S = Val.getSExtValue();
+ uint64_t Magnitude = S < 0 ? -static_cast<uint64_t>(S) : uint64_t(S);
+ Small = Magnitude < DiagnosticIntegerSeparatorThreshold;
+ }
+ } else if (Val.getActiveBits() <= 64) {
+ Small = Val.getZExtValue() < DiagnosticIntegerSeparatorThreshold;
+ }
----------------
Sirraide wrote:
```suggestion
if (Val.isSingleWord()) {
if (Signed)
Small = !Val.isMinSignedValue() && std::abs(Val.getSExtValue()) < DiagnosticIntegerSeparatorThreshold;
else
Small = Val.getZExtValue() < DiagnosticIntegerSeparatorThreshold;
}
```
This deals with the issue that `-INT_MIN` overflows and is a bit simpler imo; it also avoids hard-coding that the word size of an `APInt` is 64 bits, but granted, we do that in quite a few places elsewhere...
https://github.com/llvm/llvm-project/pull/211785
More information about the cfe-commits
mailing list