[PATCH] D157383: [clang][Diagnostics] Provide source range to integer-overflow warnings

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 16 04:46:33 PDT 2023


tbaeder accepted this revision.
tbaeder added inline comments.
This revision is now accepted and ready to land.


================
Comment at: clang/lib/AST/Interp/Interp.h:530-535
   if (S.checkingForUndefinedBehavior()) {
     SmallString<32> Trunc;
     APResult.trunc(Result.bitWidth()).toString(Trunc, 10);
     auto Loc = E->getExprLoc();
-    S.report(Loc, diag::warn_integer_constant_overflow) << Trunc << Type;
+    S.report(Loc, diag::warn_integer_constant_overflow)
+        << Trunc << Type << E->getSourceRange();
----------------
hazohelet wrote:
> tbaeder wrote:
> > hazohelet wrote:
> > > I'm not sure whether this branch takes effect.
> > > I could not find codes that takes this block, so I haven't added tests for this.
> > > 
> > > FWIW, the old interpreter does not have the corresponding `warn_integer_constant_overflow` generated against overflowing increments.
> > Is is not this: https://godbolt.org/z/eqn4Gs13q?
> That note is emitted from `S.CCEDiag` at L539.
> This warning looks like it is intended to be emitted when the function is not constexpr, but it does not appear.
>From reading the code, it makes sense to me do emit this diagnostic here, but I can't get it to trigger either because the increment operator is always evaluated standalone and not as part of a function.

For this patch, let's ignore that. The changes here are fine.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157383/new/

https://reviews.llvm.org/D157383



More information about the cfe-commits mailing list