This is the mail archive of the gcc@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]

RFC: should we use -Werror? (& sample patch to do it)


I got warning levels down to around 30 on solaris2.7 and 20 on irix6.
So I thought it might be worth a try to get -Werror installed in gcc.

There are some problems.  We don't want to -Werror stage1 when using
e.g. 2.95 to bootstrap because older GCCs gives many false positives
that have since been corrected.  Using 2.95 on stage1 yields over 350
warnings on the same solaris2.7 that gets just 30 in all of stage3
(and stage3 builds all languges, not just C!)

Thus IMHO, we should only enable -Werror in stage2 or later.  However
this means if you don't do a full bootstrap (e.g. cross-compiles or
building for embedded targets) then -Werror isn't in effect.  This
also means the automatic tester to powerpc won't detect regressions.

That's a big lose since in effect warning regressions become bootstrap
failures for most people.  So I'm open to suggestion on that front.

Anyway, another problem is we have to get to zero warnings before
using -Werror.  I propose doing it one module at a time.  The patch
below is a candidate which does this for rtl.o to start with.  If that
lasts for a week without major pandemonium, we can do more files.

I also added a mechanism to disable -Werror on a per-triplet basis or
per autoconf test basis.  E.g. if the HOST_PTR_PRINTF autoconf test
fails, you are guaranteed to get some format specifier warnings.  So I
automatically disabled -Werror in that case.  Also if a platform is
hopelessly broken, you can disable -Werror in config.gcc for that
triplet.

This patch is meant to solicit comments on both the approach and
whether -Werror is a good idea in the first place.  Its been
bootstrapped on solaris2.7 and I ensured that -Werror was only passed
to rtl.o in stage2 and later.

		--Kaveh

2001-09-04  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* Makefile.in (WERROR_FLAG, WERROR2_FLAG): New variables.
	(rtl.o): Use WERROR_FLAG.
	(STAGE2_FLAGS_TO_PASS): Pass WERROR_FLAG.

	* configure.in (gcc_AC_FUNC_PRINTF_PTR): If test fails, set
	NO_WERROR=1.
	(werror_flag): Set appropriately depending on NO_WERROR.
	
diff -rup orig/egcs-CVS20010904/gcc/Makefile.in egcs-CVS20010904/gcc/Makefile.in
--- orig/egcs-CVS20010904/gcc/Makefile.in	Fri Aug 31 15:25:25 2001
+++ egcs-CVS20010904/gcc/Makefile.in	Tue Sep  4 14:58:10 2001
@@ -89,6 +89,13 @@ BOOT_CFLAGS = -g -O2
 LOOSE_WARN = -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes
 STRICT_WARN = -Wtraditional @strict1_warn@
 STRICT2_WARN = -Wtraditional -pedantic -Wno-long-long
+# WERROR_FLAG and WERROR2_FLAG are used for setting -Werror in stage2
+# and later passes.  We only ever set -Werror in stage>=2 so that
+# we've guaranteed that the latest gcc is being used for compilation.
+# This ensures that the latest set of warnings is used and also that
+# fixes for false positives are in place.
+WERROR_FLAG = 
+WERROR2_FLAG = @werror_flag@
 
 # This is how we control whether or not the additional warnings are applied.
 .-warn = $(STRICT_WARN)
@@ -1365,7 +1372,7 @@ rtl-error.o: rtl-error.c system.h $(RTL_
    input.h toplev.h intl.h diagnostic.h
 
 rtl.o : rtl.c $(GCONFIG_H) $(SYSTEM_H) $(RTL_H) real.h $(GGC_H) errors.h
-	$(CC) -c $(ALL_CFLAGS) -DGENERATOR_FILE $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION)
+	$(CC) -c $(ALL_CFLAGS) $(WERROR_FLAG) -DGENERATOR_FILE $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION)
 
 print-rtl.o : print-rtl.c $(GCONFIG_H) $(SYSTEM_H) $(RTL_H) hard-reg-set.h \
     $(BASIC_BLOCK_H)
@@ -2938,6 +2945,7 @@ STAGE2_FLAGS_TO_PASS = \
 	CFLAGS="$(BOOT_CFLAGS)" \
 	LDFLAGS="$(BOOT_LDFLAGS)" \
 	WARN_CFLAGS="\$$(GCC_WARN_CFLAGS)" \
+	WERROR_FLAG="$(WERROR2_FLAG)" \
 	STRICT_WARN="$(STRICT2_WARN)" \
 	libdir=$(libdir) \
 	LANGUAGES="$(LANGUAGES)" \
diff -rup orig/egcs-CVS20010904/gcc/configure.in egcs-CVS20010904/gcc/configure.in
--- orig/egcs-CVS20010904/gcc/configure.in	Wed Aug 22 16:30:27 2001
+++ egcs-CVS20010904/gcc/configure.in	Tue Sep  4 15:24:34 2001
@@ -605,6 +605,9 @@ AC_SUBST(TARGET_GETGROUPS_T)
 gcc_AC_FUNC_VFPRINTF_DOPRNT
 gcc_AC_FUNC_STRSTR
 gcc_AC_FUNC_PRINTF_PTR
+if test $gcc_cv_func_printf_ptr = no ; then
+  NO_WERROR=1
+fi
 
 case "${host}" in
 *-*-uwin*)
@@ -2032,6 +2035,18 @@ AC_SUBST(slibdir)
 # Nothing to do for FLOAT_H, float_format already handled.
 objdir=`pwd`
 AC_SUBST(objdir)
+
+# This allows either specific platforms (via config.gcc) or specific
+# autoconf tests to override whether warnings become errors.
+AC_MSG_CHECKING(whether to enable -Werror in stage 2)
+if test x$NO_WERROR = x ; then
+  AC_MSG_RESULT(yes)
+  werror_flag=-Werror
+else
+  AC_MSG_RESULT(no)
+  werror_flag=
+fi
+AC_SUBST(werror_flag)
 
 # Process the language and host/target makefile fragments.
 ${CONFIG_SHELL-/bin/sh} $srcdir/configure.frag $srcdir "$subdirs" "$dep_host_xmake_file" "$dep_tmake_file"


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