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]

egcs GCC_FUNC_PRINTF_PTR subtle design flaw, and patch to fix


	The design for the egcs autoconf macro GCC_FUNC_PRINTF_PTR in
aclocal.m4 is IMHO flawed in that sometimes auto-host.h defines
HOST_PTR_PRINTF and sometimes it doesn't and expects you to get it
from machmode.h.

	As warnings are eliminated and it becomes more common to use
HOST_PTR_PRINTF, we may run into the situation where the person who
eliminated the warning only tested it on a host which has "%p" and it
inadvertently fails to work on hosts which don't support "%p" and
which also fail to include machmode.h in the right module.

	So I redesigned GCC_FUNC_PRINTF_PTR to only define a HAVE_*
type macro and when defining HOST_PTR_PRINTF in machmode.h, I check
the HAVE_* macro to conditionalize the use of "%p".

	In doing so, I already found one place (mips-tfile.c) which uses
HOST_PTR_PRINTF but which doesn't include machmode.h.  (Note that both
the original design of GCC_FUNC_PRINTF_PTR and the uses of
HOST_PTR_PRINTF in mips-tfile.c without including machmode.h were my
fault.  :-) It so happened that I tested it on OSF4 which has "%p" and
thus masked it exactly as I described above.  This patch ensures this
kind of thing won't happen again.)

	Is this okay to install?

		--Kaveh



Mon Jul  6 10:22:02 1998  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* aclocal.m4 (GCC_FUNC_PRINTF_PTR): Don't define HOST_PTR_PRINTF.
  	Instead, define a new macro HAVE_PRINTF_PTR which only signifies
	whether we have the %p format specifier or not.

	* acconfig.h: Delete stub for HOST_PTR_PRINTF, add HAVE_PRINTF_PTR.
	
	* machmode.h (HOST_PTR_PRINTF): When determining the definition,
 	check HAVE_PRINTF_PTR to see whether "%p" is okay.

	* mips-tfile.c: Include machmode.h to get HOST_PTR_PRINTF.

	* Makefile.in (mips-tfile.o): Depend on machmode.h.



diff -rup orig/egcs-CVS19980703/gcc/acconfig.h egcs-CVS19980703/gcc/acconfig.h
--- orig/egcs-CVS19980703/gcc/acconfig.h	Fri Jul  3 07:56:30 1998
+++ egcs-CVS19980703/gcc/acconfig.h	Fri Jul  3 09:09:04 1998
@@ -1,5 +1,5 @@
-/* Define to "%p" if printf supports it, else machmode.h will define it.  */
-#undef HOST_PTR_PRINTF
+/* Define if printf supports "%p".  */
+#undef HAVE_PRINTF_PTR
 
 /* Define if you want expensive run-time checks. */
 #undef ENABLE_CHECKING
diff -rup orig/egcs-CVS19980703/gcc/aclocal.m4 egcs-CVS19980703/gcc/aclocal.m4
--- orig/egcs-CVS19980703/gcc/aclocal.m4	Fri Jul  3 07:56:30 1998
+++ egcs-CVS19980703/gcc/aclocal.m4	Fri Jul  3 09:09:04 1998
@@ -78,7 +78,7 @@ main()
 	gcc_cv_func_printf_ptr=no)
 rm -f core core.* *.core])
 if test $gcc_cv_func_printf_ptr = yes ; then
-  AC_DEFINE(HOST_PTR_PRINTF, "%p")
+  AC_DEFINE(HAVE_PRINTF_PTR)
 fi
 ])
 
diff -rup orig/egcs-CVS19980703/gcc/machmode.h egcs-CVS19980703/gcc/machmode.h
--- orig/egcs-CVS19980703/gcc/machmode.h	Fri Jul  3 07:57:36 1998
+++ egcs-CVS19980703/gcc/machmode.h	Fri Jul  3 09:09:04 1998
@@ -53,10 +53,14 @@ Boston, MA 02111-1307, USA.  */
 /* Provide a default way to print an address in hex via printf.  */
 
 #ifndef HOST_PTR_PRINTF
-#define HOST_PTR_PRINTF \
-  (sizeof (int) == sizeof (char *) ? "%x" \
-   : sizeof (long) == sizeof (char *) ? "%lx" : "%llx")
-#endif
+# ifdef HAVE_PRINTF_PTR
+#  define HOST_PTR_PRINTF "%p"
+# else
+#  define HOST_PTR_PRINTF \
+    (sizeof (int) == sizeof (char *) ? "%x" \
+     : sizeof (long) == sizeof (char *) ? "%lx" : "%llx")
+# endif
+#endif /* ! HOST_PTR_PRINTF */
 
 /* Provide defaults for the way to print a HOST_WIDE_INT
    in various manners.  */
diff -rup orig/egcs-CVS19980703/gcc/mips-tfile.c egcs-CVS19980703/gcc/mips-tfile.c
--- egcs-CVS19980703/gcc/mips-tfile.c~	Fri Jul  3 07:57:38 1998
+++ egcs-CVS19980703/gcc/mips-tfile.c	Fri Jul  3 11:29:18 1998
@@ -713,6 +713,8 @@ main ()
 #include <stab.h>  /* On BSD, use the system's stab.h.  */
 #endif /* not USG */
 
+#include "machmode.h"
+
 #ifdef __GNU_STAB__
 #define STAB_CODE_TYPE enum __stab_debug_code
 #else
diff -rup orig/egcs-CVS19980703/gcc/Makefile.in egcs-CVS19980703/gcc/Makefile.in
--- egcs-CVS19980703/gcc/Makefile.in~	Fri Jul  3 09:19:53 1998
+++ egcs-CVS19980703/gcc/Makefile.in	Fri Jul  3 11:29:53 1998
@@ -1498,7 +1498,7 @@ $(out_object_file): $(out_file) $(CONFIG
 mips-tfile: mips-tfile.o version.o $(LIBDEPS)
 	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ mips-tfile.o version.o $(LIBS)
 
-mips-tfile.o : mips-tfile.c $(CONFIG_H) $(RTL_H) system.h
+mips-tfile.o : mips-tfile.c $(CONFIG_H) $(RTL_H) system.h machmode.h
 
 mips-tdump: mips-tdump.o version.o $(LIBDEPS)
 	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ mips-tdump.o version.o $(LIBS)


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