[clang] [Clang][Sema] Switch diagnostics from toString to operator<< for APSInt/APInt (PR #161474)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 1 09:00:27 PDT 2025


================
@@ -14883,14 +14880,12 @@ void Sema::CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr,
 
       // Diag message shows element size in bits and in "bytes" (platform-
       // dependent CharUnits)
-      DiagRuntimeBehavior(BaseExpr->getBeginLoc(), BaseExpr,
-                          PDiag(DiagID)
-                              << toString(index, 10, true) << AddrBits
-                              << (unsigned)ASTC.toBits(*ElemCharUnits)
-                              << toString(ElemBytes, 10, false)
-                              << toString(MaxElems, 10, false)
-                              << (unsigned)MaxElems.getLimitedValue(~0U)
-                              << IndexExpr->getSourceRange());
+      DiagRuntimeBehavior(
+          BaseExpr->getBeginLoc(), BaseExpr,
+          PDiag(DiagID) << index << AddrBits
+                        << (unsigned)ASTC.toBits(*ElemCharUnits) << ElemBytes
+                        << MaxElems << (unsigned)MaxElems.getLimitedValue(~0U)
----------------
erichkeane wrote:

it might be nice to do something with `getLimitedValue` here too? It actually has a bit of a bug (getLimitedValue is a 64 bit value, but we're casting to 32!), and is suppressing the tags here.

It would be nice if we could do some sort of 'get min of two' and start with APSInts/APInts.

EDIT: THOUGH I see that the message actually DOES have the value in it?  What is this last one actually doing/being used for in this diagnostic?

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


More information about the cfe-commits mailing list