This is the mail archive of the
mailing list for the GCC project.
[PATCH RFC] Warn when optimization flag is given without -O
- From: Alexander Monakov <amonakov at ispras dot ru>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 28 Apr 2012 18:48:22 +0400 (MSK)
- Subject: [PATCH RFC] Warn when optimization flag is given without -O
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
@@ -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)
+ && !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