================
@@ -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
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits