This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
RFA: Warn when running LTO compiler without any optimization level set
- From: Nick Clifton <nickc at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 09 Apr 2010 16:19:16 +0100
- Subject: RFA: Warn when running LTO compiler without any optimization level set
Hi Guys,
Running the LTO compiler without enabling any optimizations is not
very useful, but it can happen if the user forgets to include a -O<n>
setting on the linker command line. (Or as happened to me, a
testsuite harness has separate settings for the compiler and linker
command lines and although -flto has been added to both, -03 was only
added to the compiler command line).
The attached patch adds a warning message for this particular
circumstance:
lto1: warning: -flto used without an optimization level set - was this intentional ?
At the moment this warning can only be disabled by adding -O<n> (where
<n> is not zero), -Os or -w to the command line. I could add a
specific warning enable/disable option to control it, but this seemed
like overkill.
Tested without regressions on an i686-pc-linux-gnu toolchain.
OK to apply ?
Cheers
Nick
gcc/lto/ChangeLog
2010-04-09 Nick Clifton <nickc@redhat.com>
* lto-lang.c (lto_init): Warn if the LTO compiler is run without
any optimizations enabled.
Index: gcc/lto/lto-lang.c
===================================================================
--- gcc/lto/lto-lang.c (revision 158149)
+++ gcc/lto/lto-lang.c (working copy)
@@ -1031,6 +1031,22 @@
static bool
lto_init (void)
{
+ /* It is pointless to invoke LTO without any kind of optimization enabled.
+ So if the optimization level is zero we issue a warning message to the
+ user.
+
+ If the user is only interested in enabling specific optimizations and
+ they are bugged by this warning they can add -w to the command line.
+ FIXME: Do we need a -Wlto option to allow this warning to be enabled/
+ disabled explicitly ?
+
+ Note, we have to perform this test here, rather than in
+ opts.c:decode_options, because there is no way to tell that we are
+ running as the LTO compiler in that function. */
+ if (optimize == 0)
+ warning_at (UNKNOWN_LOCATION, 0, "-flto used on object files without an "
+ "optimization level set - was this intentional ?");
+
/* We need to generate LTO if running in WPA mode. */
flag_generate_lto = flag_wpa;