From patchwork Sat Apr 28 14:48:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [RFC] Warn when optimization flag is given without -O Date: Sat, 28 Apr 2012 04:48:22 -0000 From: Alexander Monakov X-Patchwork-Id: 155659 Message-Id: To: gcc-patches@gcc.gnu.org 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) + && !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