On Mon, 2025-06-30 at 16:47 +0000, Qing Zhao wrote:

[...snip...]

> The output with -fdiagnostics-show-context=1 is:
> 
> /home/opc/Work/GCC/latest-gcc-
> write/gcc/testsuite/gcc.dg/pr109071_7.c: In function ‘foo’:
> /home/opc/Work/GCC/latest-gcc-
> write/gcc/testsuite/gcc.dg/pr109071_7.c:12:6: warning: array
> subscript -1 is below array bounds of ‘int[10]’ [-Warray-bounds=]
>    12 |     a[i] = -1; /* { dg-warning "is below array bounds of" }
> */
>       |     ~^~~
>   ‘foo’: events 1-2
>    11 |   if (i == -1)
>       |      ^
>       |      |
>       |      (1) when the condition is evaluated to true

Looks great, but one caution: presumably "true" in this context refers
to the state of the IR when the warning is emitted, rather than what
the user wrote.  I've run into this in the analyzer;
see PR analyzer/100116 (which I don't have a good solution for, alas).

Is there a way to get at the original sense of the condition, in terms
of what the user wrote?  I'm guessing that this has been canonicalized
away long before the middle-end warnings see this.

Or perhaps the message for (1) could say exactly what condition it
considers to be true e.g.
  (1) when the condition "i == -1" is evaluated to true
or somesuch, which might give the user a better clue if the sense of
the conditional has been reversed during canonicalization/optimization.

Caveat: I didn't reread the latest version of your patch, but am just
assuming it's looking at the cfg edge flags when the warning is
emitted; sorry if I'm making a false assumption here.

> 
Dave

Reply via email to