[RFC,2/2] bootstrap: disable most warnings in stage 3

Message ID alpine.LNX.2.20.13.1808272030360.10521@monopod.intra.ispras.ru
State New
Headers show
Series
  • [1/2] configure.ac: use 'suppress' instead of 'don't'
Related show

Commit Message

Alexander Monakov Aug. 27, 2018, 6:20 p.m.
Currently bootstrap stages 2 and 3 use the same warning options, but that is
redundant: if any warnings are generated, they will be present in stage 2 (and
stop bootstrap).  By not enabling any warnings for stage 3, we would get
simple automated checking that warnings do not affect code generation.

I've checked GCC 5 managed to bootstrap in this manner, but starting from
GCC 6 we've gotten less lucky.  There's a bunch of options already confirmed
to affect code generation:

-Wnonnull/-Wrestrict/-Wformat/-Wsuggest-attribute=format (PR 86567)
-Wimplicit-fallthrough (PR 86575)
-Wsign-compare (PR 86586)

Individual bugs are linked from PR 86518.

The list is likely incomplete as usage of maybe_constant_value conditional on
some warning being enabled is a common source of divergence in the C++ frontend
(maybe_constant_value keeps a cache, so with warnings trees in the cache
may get lower uids than they otherwise would).

I imagine a possible solution to that would be making maybe_constant_value
not pollute its cache under warning context, but no idea how naive that is.

In the hope of refreshing the discussion I'm pasting a patch that implements
configure code to add the bootstrap check. In my testing only -Wsign-compare
makes bootstrap diverge.


	* Makefile.tpl (STAGE3_CONFIGURE_FLAGS): Pass --disable-build-warnings.
	* gcc/configure.ac (--disable-build-warnings): New option.
	* Makefile.in: Regenerate.
	* gcc/configure: Regenerate.

-- 
2.13.3

Comments

Joseph Myers Aug. 27, 2018, 6:56 p.m. | #1
On Mon, 27 Aug 2018, Alexander Monakov wrote:

> 	* gcc/configure.ac (--disable-build-warnings): New option.


Note that for any version of this patch actually proposed for inclusion 
(as opposed to an RFC) you'll need to include documentation in 
install.texi for the new configure option.

-- 
Joseph S. Myers
joseph@codesourcery.com
Jeff Law Aug. 27, 2018, 7:04 p.m. | #2
On 08/27/2018 12:20 PM, Alexander Monakov wrote:
> Currently bootstrap stages 2 and 3 use the same warning options, but that is

> redundant: if any warnings are generated, they will be present in stage 2 (and

> stop bootstrap).  By not enabling any warnings for stage 3, we would get

> simple automated checking that warnings do not affect code generation.

> 

> I've checked GCC 5 managed to bootstrap in this manner, but starting from

> GCC 6 we've gotten less lucky.  There's a bunch of options already confirmed

> to affect code generation:

> 

> -Wnonnull/-Wrestrict/-Wformat/-Wsuggest-attribute=format (PR 86567)

> -Wimplicit-fallthrough (PR 86575)

> -Wsign-compare (PR 86586)

At least some of these are likely mine...  The range analyzer is
reflecting ranges it discovers back into the global state.  THe fix
ought to be easy, but I haven't gotten to it yet.

jeff

Patch

diff --git a/Makefile.tpl b/Makefile.tpl
index 447d324595f..d3ee9e07397 100644
--- a/Makefile.tpl
+++ b/Makefile.tpl
@@ -452,6 +452,8 @@  STAGE1_CONFIGURE_FLAGS = --disable-intermodule $(STAGE1_CHECKING) \
 	  --disable-coverage --enable-languages="$(STAGE1_LANGUAGES)" \
 	  --disable-build-format-warnings
 
+STAGE3_CONFIGURE_FLAGS = --disable-build-warnings
+
 # When using the slow stage1 compiler disable IL verification and forcefully
 # enable it when using the stage2 compiler instead.  As we later compare
 # stage2 and stage3 we are merely avoid doing redundant work, plus we apply
diff --git a/gcc/configure.ac b/gcc/configure.ac
index a693bfa0e31..c97dc0842b3 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -482,9 +482,22 @@  AC_ARG_ENABLE(build-format-warnings,
   [],[enable_build_format_warnings=yes])
 AS_IF([test $enable_build_format_warnings = no],
       [wf_opt=-Wno-format],[wf_opt=])
+
+# In stage 3, build without most warnings so bootstrap comparison against
+# stage 2 verifies that checks for warnings do not affect code generation
+AC_ARG_ENABLE(build-warnings,
+  AS_HELP_STRING([--disable-build-warnings],
+		 [do not enable most warnings while building GCC]),
+  [],[enable_build_warnings=yes])
+
+AS_IF([test "$enable_build_warnings" = yes],
+      [warn_opt="-W -Wall -Wcast-qual"],
+      # list warnings known to affect code generation: PR bootstrap/86518
+      [warn_opt="-Wsign-compare"])
+
 ACX_PROG_CXX_WARNING_OPTS(
-	m4_quote(m4_do([-W -Wall -Wno-narrowing -Wwrite-strings ],
-		       [-Wcast-qual $wf_opt])), [loose_warn])
+	m4_quote(m4_do([$warn_opt $wf_opt -Wno-narrowing -Wwrite-strings])),
+	[loose_warn])
 ACX_PROG_CC_WARNING_OPTS(
 	m4_quote(m4_do([-Wstrict-prototypes -Wmissing-prototypes])),
 	[c_loose_warn])
diff --git a/Makefile.in b/Makefile.in
index e0dfad337a6..4d41595de3b 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -529,6 +529,8 @@  STAGE1_CONFIGURE_FLAGS = --disable-intermodule $(STAGE1_CHECKING) \
 	  --disable-coverage --enable-languages="$(STAGE1_LANGUAGES)" \
 	  --disable-build-format-warnings
 
+STAGE3_CONFIGURE_FLAGS = --disable-build-warnings
+
 # When using the slow stage1 compiler disable IL verification and forcefully
 # enable it when using the stage2 compiler instead.  As we later compare
 # stage2 and stage3 we are merely avoid doing redundant work, plus we apply
diff --git a/gcc/configure b/gcc/configure
index be6f0be6ba2..25c669df0f3 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -898,6 +898,7 @@  with_gnu_as
 with_as
 enable_largefile
 enable_build_format_warnings
+enable_build_warnings
 enable_werror_always
 enable_checking
 enable_coverage
@@ -1604,6 +1605,8 @@  Optional Features:
   --disable-largefile     omit support for large files
   --disable-build-format-warnings
                           suppress -Wformat while building GCC
+  --disable-build-warnings
+                          do not enable most warnings while building GCC
   --enable-werror-always  enable -Werror despite compiler version
   --enable-checking[=LIST]
                           enable expensive run-time checks. With LIST, enable
@@ -6666,6 +6669,24 @@  if test $enable_build_format_warnings = no; then :
 else
   wf_opt=
 fi
+
+# In stage 3, build without most warnings so bootstrap comparison against
+# stage 2 verifies that checks for warnings do not affect code generation
+# Check whether --enable-build-warnings was given.
+if test "${enable_build_warnings+set}" = set; then :
+  enableval=$enable_build_warnings;
+else
+  enable_build_warnings=yes
+fi
+
+
+if test "$enable_build_warnings" = yes; then :
+  warn_opt="-W -Wall -Wcast-qual"
+else
+  # list warnings known to affect code generation: PR bootstrap/86518
+      warn_opt="-Wsign-compare"
+fi
+
 ac_ext=cpp
 ac_cpp='$CXXCPP $CPPFLAGS'
 ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
@@ -6674,7 +6695,7 @@  ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
 
 loose_warn=
 save_CXXFLAGS="$CXXFLAGS"
-for real_option in -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual $wf_opt; do
+for real_option in $warn_opt $wf_opt -Wno-narrowing -Wwrite-strings; do
   # Do the check with the no- prefix removed since gcc silently
   # accepts any -Wno-* option on purpose
   case $real_option in
@@ -18460,7 +18481,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18463 "configure"
+#line 18484 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -18566,7 +18587,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18569 "configure"
+#line 18590 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -19731,20 +19752,20 @@  if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
 	      prelink_cmds_CXX='tpldir=Template.dir~
 		rm -rf $tpldir~
 		$CC --prelink_objects --instantiation_dir $tpldir $objs $libobjs $compile_deplibs~
-		compile_command="$compile_command `find $tpldir -name \*.o | $NL2SP`"'
+		compile_command="$compile_command `find $tpldir -name \*.o | sort | $NL2SP`"'
 	      old_archive_cmds_CXX='tpldir=Template.dir~
 		rm -rf $tpldir~
 		$CC --prelink_objects --instantiation_dir $tpldir $oldobjs$old_deplibs~
-		$AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | $NL2SP`~
+		$AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | sort | $NL2SP`~
 		$RANLIB $oldlib'
 	      archive_cmds_CXX='tpldir=Template.dir~
 		rm -rf $tpldir~
 		$CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~
-		$CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'
+		$CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'
 	      archive_expsym_cmds_CXX='tpldir=Template.dir~
 		rm -rf $tpldir~
 		$CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~
-		$CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib'
+		$CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib'
 	      ;;
 	    *) # Version 6 and above use weak symbols
 	      archive_cmds_CXX='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'