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]

[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
--- 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

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