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]: add -Wmissing-format-attribute to warning flags


Recent additions and cleanups to format attribute settings allows us
to ensure all functions have the appropriate format attribute set.
This patch adds -Wmissing-format-attribute to the warning cflags to
ensure we don't regress in this regard.

I noticed that the fixincludes directory had no warning flags at all
after being moved to the top level directory.  This patch adds them
back in.

Note 1: I included toplev.h in c-tree.h so that the appropriate macros
are defined in the right order.

Note 2: The fixincludes and libcpp bits can go in separately from the
gcc directory diagnistic bits if they're reviewed separately.

Bootstrapped on x86_64-unknown-linux-gnu with gcc-3.4 for stage1 and
sparc-sun-solaris2.7 with cc for stage1.  (This tests whether
configure correctly detects and/or avoids particular warning cflags
for stage1.)

Okay for mainline?

		Thanks,
		--Kaveh


2005-07-14  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

fixincludes:
	* Makefile.in (WARN_CFLAGS): New.
	(.c.o): Add $(WARN_CFLAGS).
	* aclocal.m4: Include ../config/warnings.m4.
	* configure.ac: Invoke ACX_PROG_CC_WARNING_OPTS,
	ACX_PROG_CC_WARNING_ALMOST_PEDANTIC and
	ACX_PROG_CC_WARNINGS_ARE_ERRORS.
	* fixopts.c (initialize_opts): Fix old-style definintion.

	* configure: Regenerate.

gcc:
	* Makefile.in (STRICT2_WARN): Add -Wmissing-format-attribute.
	(C_TREE_H): Update dependencies.
	* c-tree.h: Include toplev.h.
	* configure.ac: Check for -Wmissing-format-attribute.
	* diagnostic.h (diagnostic_set_info): Add format attribute.
	* rtl-error.c (diagnostic_for_asm): Likewise.
	
	* configure: Regenerate.
	
libcpp:
	* configure.ac (ACX_PROG_CC_WARNING_OPTS): add
	-Wmissing-format-attribute.

	* configure: Regenerate.

diff -rup orig/egcc-CVS20050713/fixincludes/Makefile.in egcc-CVS20050713/fixincludes/Makefile.in
--- orig/egcc-CVS20050713/fixincludes/Makefile.in	2005-03-21 21:09:52.000000000 -0500
+++ egcc-CVS20050713/fixincludes/Makefile.in	2005-07-14 10:58:11.000000000 -0400
@@ -29,6 +29,7 @@ STAMP = echo timestamp >
 
 CC = @CC@
 CFLAGS = @CFLAGS@
+WARN_CFLAGS = @WARN_CFLAGS@ @WARN_PEDANTIC@ @WERROR@
 LDFLAGS = @LDFLAGS@
 INCLUDES = -I. -I$(srcdir) -I../include -I$(srcdir)/../include
 FIXINC_CFLAGS = -DHAVE_CONFIG_H $(INCLUDES)
@@ -68,7 +69,7 @@ default : all
 # Now figure out from those variables how to compile and link.
 
 .c.o:
-	$(CC) -c $(CFLAGS) $(CPPFLAGS) $(FIXINC_CFLAGS) $<
+	$(CC) -c $(CFLAGS) $(WARN_CFLAGS) $(CPPFLAGS) $(FIXINC_CFLAGS) $<
 
 # The only suffixes we want for implicit rules are .c and .o.
 .SUFFIXES:
diff -rup orig/egcc-CVS20050713/fixincludes/aclocal.m4 egcc-CVS20050713/fixincludes/aclocal.m4
--- orig/egcc-CVS20050713/fixincludes/aclocal.m4	2005-05-19 22:50:13.000000000 -0400
+++ egcc-CVS20050713/fixincludes/aclocal.m4	2005-07-14 11:01:07.000000000 -0400
@@ -1,6 +1,7 @@
 sinclude(../config/acx.m4)
 sinclude(../config/gettext.m4)
 sinclude(../config/progtest.m4)
+sinclude(../config/warnings.m4)
 
 dnl See whether we need a declaration for a function.
 dnl The result is highly dependent on the INCLUDES passed in, so make sure
diff -rup orig/egcc-CVS20050713/fixincludes/configure.ac egcc-CVS20050713/fixincludes/configure.ac
--- orig/egcc-CVS20050713/fixincludes/configure.ac	2005-04-11 17:51:41.000000000 -0400
+++ egcc-CVS20050713/fixincludes/configure.ac	2005-07-14 10:58:42.000000000 -0400
@@ -6,6 +6,18 @@ AC_CONFIG_AUX_DIR(..)
 AC_CANONICAL_SYSTEM
 AC_PROG_CC
 
+# Figure out what compiler warnings we can enable.
+# See config/warnings.m4 for details.
+
+ACX_PROG_CC_WARNING_OPTS([-W -Wall -Wwrite-strings -Wstrict-prototypes \
+			  -Wmissing-prototypes -Wold-style-definition \
+			  -Wmissing-format-attribute])
+ACX_PROG_CC_WARNING_ALMOST_PEDANTIC([-Wno-long-long])
+
+# Only enable with --enable-werror-always until existing warnings are
+# corrected.
+ACX_PROG_CC_WARNINGS_ARE_ERRORS([manual])
+
 # Determine the noncanonical target name, for directory use.
 ACX_NONCANONICAL_TARGET
 
diff -rup orig/egcc-CVS20050713/fixincludes/fixopts.c egcc-CVS20050713/fixincludes/fixopts.c
--- orig/egcc-CVS20050713/fixincludes/fixopts.c	2004-10-15 03:58:38.000000000 -0400
+++ egcc-CVS20050713/fixincludes/fixopts.c	2005-07-14 11:09:58.000000000 -0400
@@ -26,7 +26,7 @@ ENV_TABLE
 #undef _ENV_
 
 void
-initialize_opts ()
+initialize_opts (void)
 {
   static const char var_not_found[] =
 #ifndef __STDC__
diff -rup orig/egcc-CVS20050713/gcc/Makefile.in egcc-CVS20050713/gcc/Makefile.in
--- orig/egcc-CVS20050713/gcc/Makefile.in	2005-07-10 00:04:48.000000000 -0400
+++ egcc-CVS20050713/gcc/Makefile.in	2005-07-14 10:00:09.000000000 -0400
@@ -176,7 +176,7 @@ LOOSE_WARN = -W -Wall -Wwrite-strings -W
 STRICT_WARN = @strict1_warn@
 WERROR_FLAGS = @WERROR@
 STRICT2_WARN = -pedantic -Wno-long-long -Wno-variadic-macros \
-  -Wold-style-definition $(WERROR_FLAGS)
+  -Wold-style-definition -Wmissing-format-attribute $(WERROR_FLAGS)
 
 # This is set by --enable-checking.  The idea is to catch forgotten
 # "extern" tags in header files.
@@ -738,7 +738,7 @@ TIMEVAR_H = timevar.h timevar.def
 INSN_ATTR_H = insn-attr.h $(srcdir)/insn-addr.h $(srcdir)/varray.h
 C_COMMON_H = c-common.h $(SPLAY_TREE_H) $(CPPLIB_H) $(GGC_H)
 C_PRAGMA_H = c-pragma.h $(CPPLIB_H)
-C_TREE_H = c-tree.h $(C_COMMON_H)
+C_TREE_H = c-tree.h $(C_COMMON_H) toplev.h $(DIAGNOSTIC_H)
 SYSTEM_H = system.h hwint.h $(srcdir)/../include/libiberty.h
 PREDICT_H = predict.h predict.def
 CPPLIB_H = $(srcdir)/../libcpp/include/line-map.h \
diff -rup orig/egcc-CVS20050713/gcc/c-tree.h egcc-CVS20050713/gcc/c-tree.h
--- orig/egcc-CVS20050713/gcc/c-tree.h	2005-07-05 22:33:14.000000000 -0400
+++ egcc-CVS20050713/gcc/c-tree.h	2005-07-14 10:00:09.000000000 -0400
@@ -23,6 +23,7 @@ Software Foundation, 51 Franklin Street,
 #define GCC_C_TREE_H
 
 #include "c-common.h"
+#include "toplev.h"
 #include "diagnostic.h"
 
 /* struct lang_identifier is private to c-decl.c, but langhooks.c needs to
diff -rup orig/egcc-CVS20050713/gcc/configure.ac egcc-CVS20050713/gcc/configure.ac
--- orig/egcc-CVS20050713/gcc/configure.ac	2005-07-08 21:18:59.000000000 -0400
+++ egcc-CVS20050713/gcc/configure.ac	2005-07-14 10:00:09.000000000 -0400
@@ -330,7 +330,6 @@ if test $ac_cv_prog_cc_w_no_long_long = 
    && test $ac_cv_prog_cc_w_no_variadic_macros = yes ; then
   strict1_warn="-pedantic -Wno-long-long -Wno-variadic-macros"
 fi
-AC_SUBST(strict1_warn)
 
 # Add -Wold-style-definition if it's accepted
 AC_CACHE_CHECK(
@@ -347,6 +346,21 @@ if test $ac_cv_prog_cc_w_old_style_defin
   strict1_warn="${strict1_warn} -Wold-style-definition"
 fi
 
+# Add -Wmissing-format-attribute if it's accepted
+AC_CACHE_CHECK(
+  [whether ${CC} accepts -Wmissing-format-attribute],
+  [ac_cv_prog_cc_w_missing_format_attribute],
+  [save_CFLAGS="$CFLAGS"
+  CFLAGS="-Wmissing-format-attribute"
+  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[]])],
+                    [ac_cv_prog_cc_w_missing_format_attribute=yes],
+                    [ac_cv_prog_cc_w_missing_format_attribute=no])
+  CFLAGS="$save_CFLAGS"
+  ])
+if test $ac_cv_prog_cc_w_missing_format_attribute = yes ; then
+  strict1_warn="${strict1_warn} -Wmissing-format-attribute"
+fi
+
 # Enable -Werror, period.
 AC_ARG_ENABLE(werror_always, 
 [  --enable-werror-always         enable -Werror always], [],
@@ -356,6 +370,8 @@ if test x${enable_werror_always} = xyes 
   WERROR=-Werror
 fi
 
+AC_SUBST(strict1_warn)
+
 # If the native compiler is GCC, we can enable warnings even in stage1.  
 # That's useful for people building cross-compilers, or just running a
 # quick `make'.
diff -rup orig/egcc-CVS20050713/gcc/diagnostic.h egcc-CVS20050713/gcc/diagnostic.h
--- orig/egcc-CVS20050713/gcc/diagnostic.h	2005-06-30 21:23:37.000000000 -0400
+++ egcc-CVS20050713/gcc/diagnostic.h	2005-07-14 10:00:09.000000000 -0400
@@ -181,8 +181,10 @@ extern void diagnostic_report_current_mo
 extern void diagnostic_report_current_function (diagnostic_context *);
 extern void diagnostic_report_diagnostic (diagnostic_context *,
 					  diagnostic_info *);
+#ifdef ATTRIBUTE_GCC_DIAG
 extern void diagnostic_set_info (diagnostic_info *, const char *, va_list *,
-				 location_t, diagnostic_t);
+				 location_t, diagnostic_t) ATTRIBUTE_GCC_DIAG(2,0);
+#endif
 extern char *diagnostic_build_prefix (diagnostic_info *);
 
 /* Pure text formatting support functions.  */
diff -rup orig/egcc-CVS20050713/gcc/rtl-error.c egcc-CVS20050713/gcc/rtl-error.c
--- orig/egcc-CVS20050713/gcc/rtl-error.c	2005-06-25 22:37:22.000000000 -0400
+++ egcc-CVS20050713/gcc/rtl-error.c	2005-07-14 10:00:09.000000000 -0400
@@ -34,7 +34,7 @@ Boston, MA 02110-1301, USA.  */
 #include "diagnostic.h"
 
 static location_t location_for_asm (rtx);
-static void diagnostic_for_asm (rtx, const char *, va_list *, diagnostic_t);
+static void diagnostic_for_asm (rtx, const char *, va_list *, diagnostic_t) ATTRIBUTE_GCC_DIAG(2,0);
 
 /* Figure the location of the given INSN.  */
 static location_t
diff -rup orig/egcc-CVS20050713/libcpp/configure.ac egcc-CVS20050713/libcpp/configure.ac
--- orig/egcc-CVS20050713/libcpp/configure.ac	2005-06-13 22:07:49.000000000 -0400
+++ egcc-CVS20050713/libcpp/configure.ac	2005-07-14 10:31:09.000000000 -0400
@@ -22,7 +22,8 @@ AC_CHECK_PROGS([AUTOHEADER], [autoheader
 # See config/warnings.m4 for details.
 
 ACX_PROG_CC_WARNING_OPTS([-W -Wall -Wwrite-strings -Wstrict-prototypes \
-			  -Wmissing-prototypes -Wold-style-definition])
+			  -Wmissing-prototypes -Wold-style-definition \
+			  -Wmissing-format-attribute])
 ACX_PROG_CC_WARNING_ALMOST_PEDANTIC([-Wno-long-long])
 
 # Only enable with --enable-werror-always until existing warnings are


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