public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Separate warning/error thresholds for -Wfoo=<n>
@ 2022-12-06 15:52 Alexander Monakov
  2022-12-06 16:18 ` Richard Biener
  0 siblings, 1 reply; 3+ messages in thread
From: Alexander Monakov @ 2022-12-06 15:52 UTC (permalink / raw)
  To: gcc; +Cc: David Malcolm

Greetings, David, community,

I'd like to get your input on how GCC command line interface should support
making a "tiered" warning like -Warray-bounds={1,2} an error for "tier 1"
where fewer false positives are expected, and a plain warning otherwise.

There was a recent thread mentioning the current limitation [1]:

> This also shows nicely why I don't like warnings with levels, what if I want
> -Werror=array-bounds=2 + -Warray-bounds=1?

Also in PR 48088 [2] there was a request to make it work for stack size usage:

> Stumbled on this bug today. I tried to use it in more intricate way:
> 
>     -Wframe-larger-than=4096 -Werror=frame-larger-than=32768
> 
> which would only warn about any stack more than 4096+, but would fail on
> 32768+.
> 
> Does it make sense to implement desired behaviour?
> I guess it's not many '>=number' style options in gcc.

A problem with implementing DWIM semantics like above for -Wfoo=k -Werror=foo=n
combination is that technically it changes its current meaning.

If we don't want to risk that, an alternative is to introduce a new option
for selecting error threshold for a tiered warning, for example:

  -Warray-bounds=2 -Werror-level=array-bounds=1

Implementation-wise, we would need to extend common.opt language to annotate
which tier is more inclusive (generally smaller 'n' means fewer warnings, but
for -Wstack-usage and -Wstrict-aliasing it's the other way around).

Opinions? Does anybody envision problems with going the DWIM way?

Thanks.
Alexander

[1] https://inbox.sourceware.org/gcc-patches/2552ab22-916f-d0fe-2c78-d482f6ad8412@lauterbach.com/
[2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48088#c5

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Separate warning/error thresholds for -Wfoo=<n>
  2022-12-06 15:52 Separate warning/error thresholds for -Wfoo=<n> Alexander Monakov
@ 2022-12-06 16:18 ` Richard Biener
  2022-12-06 16:43   ` Alexander Monakov
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2022-12-06 16:18 UTC (permalink / raw)
  To: Alexander Monakov; +Cc: gcc, David Malcolm

On Tue, Dec 6, 2022 at 4:53 PM Alexander Monakov via Gcc
<gcc@gcc.gnu.org> wrote:
>
> Greetings, David, community,
>
> I'd like to get your input on how GCC command line interface should support
> making a "tiered" warning like -Warray-bounds={1,2} an error for "tier 1"
> where fewer false positives are expected, and a plain warning otherwise.
>
> There was a recent thread mentioning the current limitation [1]:
>
> > This also shows nicely why I don't like warnings with levels, what if I want
> > -Werror=array-bounds=2 + -Warray-bounds=1?
>
> Also in PR 48088 [2] there was a request to make it work for stack size usage:
>
> > Stumbled on this bug today. I tried to use it in more intricate way:
> >
> >     -Wframe-larger-than=4096 -Werror=frame-larger-than=32768
> >
> > which would only warn about any stack more than 4096+, but would fail on
> > 32768+.
> >
> > Does it make sense to implement desired behaviour?
> > I guess it's not many '>=number' style options in gcc.
>
> A problem with implementing DWIM semantics like above for -Wfoo=k -Werror=foo=n
> combination is that technically it changes its current meaning.
>
> If we don't want to risk that, an alternative is to introduce a new option
> for selecting error threshold for a tiered warning, for example:
>
>   -Warray-bounds=2 -Werror-level=array-bounds=1
>
> Implementation-wise, we would need to extend common.opt language to annotate
> which tier is more inclusive (generally smaller 'n' means fewer warnings, but
> for -Wstack-usage and -Wstrict-aliasing it's the other way around).

Implementation-wise one could do a similar trick as we have for
global_options vs. global_options_set - add a global_options_error copy (ick!)
(and global_options_error_set!?) and have the logic that decides whether
a warning is an error pick that set.  Of course it's the actual pass that looks
at flag_xyz which holds the magic number so that pass would need to be able
to see whether it needs to look at both numbers.

Btw, does '-Werror=array-bounds=2' imply that =1 kinds are diagnosed as
warning?  Does it enable -Warray-bounds=2?

I think the DWIM behavior isn't all that clear and probably depends on the
actual option we want to make it work.

Richard.

>
> Opinions? Does anybody envision problems with going the DWIM way?
>
> Thanks.
> Alexander
>
> [1] https://inbox.sourceware.org/gcc-patches/2552ab22-916f-d0fe-2c78-d482f6ad8412@lauterbach.com/
> [2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48088#c5

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Separate warning/error thresholds for -Wfoo=<n>
  2022-12-06 16:18 ` Richard Biener
@ 2022-12-06 16:43   ` Alexander Monakov
  0 siblings, 0 replies; 3+ messages in thread
From: Alexander Monakov @ 2022-12-06 16:43 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc, David Malcolm


On Tue, 6 Dec 2022, Richard Biener via Gcc wrote:

> Implementation-wise one could do a similar trick as we have for
> global_options vs. global_options_set - add a global_options_error copy (ick!)
> (and global_options_error_set!?) and have the logic that decides whether
> a warning is an error pick that set.  Of course it's the actual pass that looks
> at flag_xyz which holds the magic number so that pass would need to be able
> to see whether it needs to look at both numbers.

I'm hoping to come up with a reasonably elegant way to implement this.

> Btw, does '-Werror=array-bounds=2' imply that =1 kinds are diagnosed as
> warning?

No, =1 kinds are diagnosed as error as well.

> Does it enable -Warray-bounds=2?

Yes, -Werror=array-bounds=2 is simply decomposed into -Warray-bounds=2
-Werror=array-bounds= (since PR 48088 was fixed).

> I think the DWIM behavior isn't all that clear and probably depends on the
> actual option we want to make it work.

Yeah, I guess there will be differences of opinion here, and I'm interested
to reach community consensus. Let's say I'm mostly interested in supporting

  -Warray-bounds=2 -Werror=array-bounds=1

(errors for most certain OOB accesses, warnings otherwise).

Alexander

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-12-06 16:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-06 15:52 Separate warning/error thresholds for -Wfoo=<n> Alexander Monakov
2022-12-06 16:18 ` Richard Biener
2022-12-06 16:43   ` Alexander Monakov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).