This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH RFC] Warn when optimization flag is given without -O


On Sat, Apr 28, 2012 at 4:48 PM, Alexander Monakov <amonakov@ispras.ru> wrote:
>
> Looks like people who want to play with optimization options are still tripped
> by the fact that optimizations are not enabled unless -O is given (even though
> it's documented in the manual now). ?Can we add a warning for that like below?
>
> Untested beside bubblestrap. ?I suppose this will produce noise for -O0
> torture testsuite — what is the recommended way to fix that?
>
> diff --git a/gcc/opts-common.c b/gcc/opts-common.c
> index 354bce0..a18a89d 100644
> --- a/gcc/opts-common.c
> +++ b/gcc/opts-common.c
> @@ -1056,6 +1056,11 @@ read_cmdline_option (struct gcc_options *opts,
> ? if (!handle_option (opts, opts_set, decoded, lang_mask, DK_UNSPECIFIED,
> ? ? ? ? ? ? ? ? ? ? ?loc, handlers, false, dc))
> ? ? error_at (loc, "unrecognized command line option %qs", opt);
> +
> + ?if ((option->flags & CL_OPTIMIZATION)

That's surely too coarse - you will warn about options that _will_
have an effect.
There is currently no easy way to glob all affected options.

I don't think we want to warn about -O2 -ftree-pre -O0 either, nor
about -fno-tree-pre.

Overall I would expect people to have noticed that with -O0 these options have
no effect when they've gone all the way to figure out the separate optimization
options, no?

Thanks,
Richard.

> + ? ? ?&& !opts->x_optimize)
> + ? ?warning_at (loc, 0, "optimization option %qs has no effect "
> + ? ? ? ? ? ? ? "at zero -O level", opt);
> ?}
>
> ?/* Set any field in OPTS, and OPTS_SET if not NULL, for option


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]