Subject: Re: K&R vs. ANSI call conventions (was Re: a new KNF)
To: None <tech-toolchain@netbsd.org>
From: ITOH Yasufumi <itohy@netbsd.org>
List: tech-toolchain
Date: 02/18/2000 16:37:55
In article <Pine.NEB.4.21.0002171120570.26938-100000@shark.int.duh.org>
tv@pobox.com writes:

> This is already broken, as the shared C library is ALREADY ANSI CODE, thanks
> to the gcc extension of ANSI prototypes with K&R functions.

In order to avoid this sort of mistakes, I propose the following
patch to gcc and to add -Wabi-breakage to library/kernel makefiles.
We already have -Werror and if we write library/kernel in current KNF,
breaking ABI becomes impossible.

This change doesn't affect any strictly conforming programs, and I
think it does no harm.

Thoughts?
-- 
ITOH, Yasufumi <itohy@netbsd.org>

diff -uF^[a-zA-Z_][a-z 	A-Z0-9_]*(.*[^;]$ gnu/dist/gcc/c-decl.c.orig gnu/dist/gcc/c-decl.c
--- gnu/dist/gcc/c-decl.c.orig	Tue Aug 25 20:05:53 1998
+++ gnu/dist/gcc/c-decl.c	Fri Feb 18 16:05:46 2000
@@ -577,6 +577,10 @@ static void layout_array_type		PROTO((tr
 
 int warn_unknown_pragmas = 0; /* Tri state variable.  */  
 
+/* Warn if the ABI is not ompatible between ANSI/traditional syntax */
+
+int warn_abi_breakage;
+
 /* Warn about comparison of signed and unsigned values.
    If -1, neither -Wsign-compare nor -Wno-sign-compare has been specified.  */
 
@@ -817,6 +821,8 @@ c_decode_option (argc, argv)
     warn_unknown_pragmas = 2;
   else if (!strcmp (p, "-Wno-unknown-pragmas"))
     warn_unknown_pragmas = 0;
+  else if (!strcmp (p, "-Wabi-breakage"))
+    warn_abi_breakage = 1;
   else if (!strcmp (p, "-Wall"))
     {
 /* XXX FIXME: bogus warnings center around this.  Disable until next import. */
@@ -6864,7 +6870,7 @@ store_parm_decls ()
 			  < TYPE_PRECISION (integer_type_node))
 			DECL_ARG_TYPE (parm) = integer_type_node;
 #endif
-		      if (pedantic)
+		      if (pedantic || warn_abi_breakage)
 			{
 			  pedwarn ("promoted argument `%s' doesn't match prototype",
 				   IDENTIFIER_POINTER (DECL_NAME (parm)));
diff -uF^[a-zA-Z_][a-z 	A-Z0-9_]*(.*[^;]$ gnu/dist/gcc/toplev.c.orig gnu/dist/gcc/toplev.c
--- gnu/dist/gcc/toplev.c.orig	Tue Jun 29 08:57:12 1999
+++ gnu/dist/gcc/toplev.c	Fri Feb 18 16:05:45 2000
@@ -971,6 +971,7 @@ void (*incomplete_decl_finalize_hook) ()
   { "-fshort-enums", "Use the smallest fitting integer to hold enums"},
   { "-fno-short-enums", "" },
 
+  { "-Wabi-breakage", "Warn about ABI compatibility" },
   { "-Wall", "Enable most warning messages" },
   { "-Wbad-function-cast",
     "Warn about casting functions to incompatible types" },