This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
egcs, PATCH for variable argument function call infrastructure ...
- To: law at cygnus dot com
- Subject: egcs, PATCH for variable argument function call infrastructure ...
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Date: Thu, 26 Mar 1998 10:13:36 -0500 (EST)
- Cc: egcs at cygnus dot com, ghazi at caip dot rutgers dot edu
I've created a patch included below which implements
infrastructure to support variable argument function calls in a
consistent way. In so doing, I've moved the inclusion of
stdarg.h/varargs.h into system.h for several reasons.
1. Since I'm going to have to add them to a bunch of new files, I felt
it was included often enough to be in system.h
2. Since there was an ordering dependency with stdio.h, we should
make this only appear in one file to reduce maintenance overhead.
3. Since the handling of stdarg.h/varargs.h is convoluted, we should
encourage one consistent method for handling it.
I've also included a definition of the macro VFPRINTF() in
system.h.
However, I put the PRINTF_ATTRIBUTE* macro definitions in
gansidecl.h since they are generally to be used in conjunction with the
PVPROTO() macro (which is also defined in gansidecl.h) and also because
as a compiler feature test (i.e. not an autoconf test), it felt more
correct to place them in gansidecl.h.
If this is acceptable, my next patch will convert gen*.c to
using this mechanism. Is this okay to install?
--Kaveh
Wed Mar 25 11:22:42 1998 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* system.h: Include stdarg.h/varargs.h before stdio.h and comment
that doing so is necessary.
(VFPRINTF): New macro to handle printing of variable arguments by
using vfprintf() or an alternative.
* gansidecl.h: Define macro PRINTF_ATTRIBUTE to use __attribute__
format __printf__ when using gcc >= v2.7. Define PRINTF_ATTRIBUTE_1,
PRINTF_ATTRIBUTE_2 and PRINTF_ATTRIBUTE_3 in terms of PRINTF_ATTRIBUTE.
* calls.c: Remove inclusion of stdarg.h/varargs.h.
* combine.c: Likewise.
* emit-rtl.c: Likewise.
* final.c: Likewise.
* gcc.c: Likewise.
* genattrtab.c: Likewise.
* prefix.c: Likewise.
* regmove.c: Likewise.
* toplev.c: Likewise.
* tree.c: Likewise.
diff -rup orig/egcs-980321/gcc/calls.c egcs-980321/gcc/calls.c
--- orig/egcs-980321/gcc/calls.c Fri Mar 20 09:57:44 1998
+++ egcs-980321/gcc/calls.c Wed Mar 25 10:56:54 1998
@@ -19,11 +19,6 @@ the Free Software Foundation, 59 Temple
Boston, MA 02111-1307, USA. */
#include "config.h"
-#ifdef __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
#include "system.h"
#include "rtl.h"
#include "tree.h"
diff -rup orig/egcs-980321/gcc/combine.c egcs-980321/gcc/combine.c
--- orig/egcs-980321/gcc/combine.c Fri Mar 20 09:57:47 1998
+++ egcs-980321/gcc/combine.c Wed Mar 25 10:57:06 1998
@@ -75,12 +75,6 @@ Boston, MA 02111-1307, USA. */
combine anyway. */
#include "config.h"
-#ifdef __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
/* stdio.h must precede rtl.h for FFS. */
#include "system.h"
diff -rup orig/egcs-980321/gcc/emit-rtl.c egcs-980321/gcc/emit-rtl.c
--- orig/egcs-980321/gcc/emit-rtl.c Fri Mar 20 09:57:53 1998
+++ egcs-980321/gcc/emit-rtl.c Wed Mar 25 10:57:20 1998
@@ -35,11 +35,6 @@ Boston, MA 02111-1307, USA. */
is the kind of rtx's they make and what arguments they use. */
#include "config.h"
-#ifdef __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
#include "system.h"
#include "rtl.h"
#include "tree.h"
diff -rup orig/egcs-980321/gcc/final.c egcs-980321/gcc/final.c
--- orig/egcs-980321/gcc/final.c Fri Mar 20 09:58:00 1998
+++ egcs-980321/gcc/final.c Wed Mar 25 10:57:29 1998
@@ -45,11 +45,6 @@ Boston, MA 02111-1307, USA. */
FUNCTION_EPILOGUE. Those instructions never exist as rtl. */
#include "config.h"
-#ifdef __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
#include "system.h"
#include "tree.h"
diff -rup orig/egcs-980321/gcc/gansidecl.h egcs-980321/gcc/gansidecl.h
--- orig/egcs-980321/gcc/gansidecl.h Sat Feb 7 19:48:07 1998
+++ egcs-980321/gcc/gansidecl.h Wed Mar 25 11:13:53 1998
@@ -34,6 +34,19 @@ Boston, MA 02111-1307, USA. */
#endif
#endif
+/* Test to see if we can use this compiler feature. */
+#ifndef PRINTF_ATTRIBUTE
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
+# define PRINTF_ATTRIBUTE(m, n)
+# else
+# define PRINTF_ATTRIBUTE(m, n) __attribute__ ((format (__printf__, m, n)))
+# endif
+#endif
+
+#define PRINTF_ATTRIBUTE_1 PRINTF_ATTRIBUTE(1, 2)
+#define PRINTF_ATTRIBUTE_2 PRINTF_ATTRIBUTE(2, 3)
+#define PRINTF_ATTRIBUTE_3 PRINTF_ATTRIBUTE(3, 4)
+
#ifndef VPROTO
#ifdef __STDC__
#define PVPROTO(ARGS) ARGS
diff -rup orig/egcs-980321/gcc/gcc.c egcs-980321/gcc/gcc.c
--- orig/egcs-980321/gcc/gcc.c Fri Mar 20 09:58:03 1998
+++ egcs-980321/gcc/gcc.c Wed Mar 25 10:57:53 1998
@@ -32,12 +32,6 @@ Once it knows which kind of compilation
compilation is specified by a string called a "spec". */
#include "config.h"
-
-#ifdef __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
#include "system.h"
#include <signal.h>
#include <sys/stat.h>
diff -rup orig/egcs-980321/gcc/genattrtab.c egcs-980321/gcc/genattrtab.c
--- orig/egcs-980321/gcc/genattrtab.c Wed Mar 25 11:03:13 1998
+++ egcs-980321/gcc/genattrtab.c Wed Mar 25 10:58:11 1998
@@ -97,11 +97,6 @@ Boston, MA 02111-1307, USA. */
#include "hconfig.h"
/* varargs must always be included after *config.h. */
-#ifdef __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
#include "system.h"
#include "rtl.h"
#include "insn-config.h" /* For REGISTER_CONSTRAINTS */
diff -rup orig/egcs-980321/gcc/prefix.c egcs-980321/gcc/prefix.c
--- orig/egcs-980321/gcc/prefix.c Fri Mar 20 09:58:14 1998
+++ egcs-980321/gcc/prefix.c Wed Mar 25 10:58:45 1998
@@ -64,11 +64,6 @@ Boston, MA 02111-1307, USA. */
#include "config.h"
-#ifdef __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
#include "system.h"
#ifdef _WIN32
#include <windows.h>
diff -rup orig/egcs-980321/gcc/regmove.c egcs-980321/gcc/regmove.c
--- orig/egcs-980321/gcc/regmove.c Fri Mar 20 09:58:23 1998
+++ egcs-980321/gcc/regmove.c Wed Mar 25 10:59:00 1998
@@ -24,12 +24,6 @@ the Free Software Foundation, 675 Mass A
instruction to avoid the move instruction. */
#include "config.h"
-#ifdef __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
/* stdio.h must precede rtl.h for FFS. */
#include "system.h"
diff -rup orig/egcs-980321/gcc/system.h egcs-980321/gcc/system.h
--- orig/egcs-980321/gcc/system.h Sat Feb 28 01:11:52 1998
+++ egcs-980321/gcc/system.h Wed Mar 25 10:54:47 1998
@@ -7,6 +7,13 @@
#ifndef __GCC_SYSTEM_H__
#define __GCC_SYSTEM_H__
+#ifdef __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+/* On some systems stdio.h includes stdarg.h;
+ we must bring in varargs.h first. */
#include <stdio.h>
#include <ctype.h>
@@ -187,5 +194,28 @@ extern void free ();
#ifdef NEED_DECLARATION_GETENV
extern char *getenv ();
#endif
+
+#ifdef HAVE_VPRINTF
+# define VFPRINTF(stream, format, args) vfprintf(stream, format, args)
+#else /* ! HAVE_VPRINTF */
+# ifdef HAVE_DOPRNT
+# define VFPRINTF(stream, format, args) _doprnt(format, args, stream)
+# else /* ! HAVE_DOPRNT */
+# define VFPRINTF(stream, format, args) \
+ do { \
+ char * a0 = va_arg(args, char *); \
+ char * a1 = va_arg(args, char *); \
+ char * a2 = va_arg(args, char *); \
+ char * a3 = va_arg(args, char *); \
+ char * a4 = va_arg(args, char *); \
+ char * a5 = va_arg(args, char *); \
+ char * a6 = va_arg(args, char *); \
+ char * a7 = va_arg(args, char *); \
+ char * a8 = va_arg(args, char *); \
+ char * a9 = va_arg(args, char *); \
+ fprintf (stream, format, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); \
+ } while (0)
+# endif /* HAVE_DOPRNT */
+#endif /* HAVE_VPRINTF */
#endif /* __GCC_SYSTEM_H__ */
diff -rup orig/egcs-980321/gcc/toplev.c egcs-980321/gcc/toplev.c
--- orig/egcs-980321/gcc/toplev.c Fri Mar 20 09:58:38 1998
+++ egcs-980321/gcc/toplev.c Wed Mar 25 10:59:11 1998
@@ -24,11 +24,6 @@ Boston, MA 02111-1307, USA. */
Error messages and low-level interface to malloc also handled here. */
#include "config.h"
-#ifdef __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
#undef FLOAT /* This is for hpux. They should change hpux. */
#undef FFS /* Some systems define this in param.h. */
#include "system.h"
diff -rup orig/egcs-980321/gcc/tree.c egcs-980321/gcc/tree.c
--- orig/egcs-980321/gcc/tree.c Fri Mar 20 09:58:39 1998
+++ egcs-980321/gcc/tree.c Wed Mar 25 10:59:21 1998
@@ -34,11 +34,6 @@ Boston, MA 02111-1307, USA. */
by all passes of the compiler. */
#include "config.h"
-#ifdef __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
#include "system.h"
#include <setjmp.h>
#include "flags.h"