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]

Re: gcc -E -traditional broken


On Mon, Dec 11, 2000 at 07:37:32PM +0000, Neil Booth wrote:
> Zack Weinberg wrote:-
> 
> > No, it's an oversight.
> 
> God, tracking this down is a nightmare.  tradcpp is a real POS.
> 
> I think I know what it is.  tradcpp uses '\0' to indicate the end of
> input buffers (not that it always bothers to check, but still...).
> Your <ctype.h> patch redefined is_nvspace to include '\0', since that
> is what cpplib wants.  However, is_nvspace is used by SKIP_WHITE_SPACE
> in tradcpp.c too.  I think you can guess the rest... :-)

That might do it, but I was avoiding work last night and fixed it
another way.  See what you think of this.  (Please pick up the test
cases even if you don't want the patch.)

zw

	* tradcif.y (%union): Remove unused member.
	* tradcpp.c (rescan): Check ibp against limit after returning
	from macroexpand.
	* gcc.dg/cpp/defined.c: Augment.
	* gcc.dg/cpp/tr-defined.c: New.
	
===================================================================
Index: tradcif.y
--- tradcif.y	2000/12/08 03:00:24	1.6
+++ tradcif.y	2000/12/11 22:23:10
@@ -45,7 +45,6 @@ Foundation, 59 Temple Place - Suite 330,
 
 %union {
   struct constant {long value; int unsignedp;} integer;
-  int voidval;
   char *sval;
 }
 
===================================================================
Index: tradcpp.c
--- tradcpp.c	2000/12/08 18:42:13	1.23
+++ tradcpp.c	2000/12/11 22:23:11
@@ -1673,7 +1673,11 @@ randomchar:
 	       a new level on it.  */
 	    obp = op->bufp;
 	    RECACHE;
-	    break;
+	    if (ibp < limit)
+	      break;
+	    /* macroexpand has put us at the end of the buffer */
+	    *op->bufp++ = '\0';
+	    goto ending;
 	  }
 hashcollision:
 	       ;
===================================================================
Index: testsuite/gcc.dg/cpp/defined.c
--- testsuite/gcc.dg/cpp/defined.c	2000/10/29 17:43:57	1.1
+++ testsuite/gcc.dg/cpp/defined.c	2000/12/11 22:23:13
@@ -6,15 +6,51 @@
 
 /*  Source: Neil Booth, 29 Oct 2000.  */
 
+#define defined			/* { dg-error "defined" } */
+
 /* No diagnostics, though you could argue there should be.  */
 #if defined defined
 #error defined is defined!
 #endif
 
-#define defined			/* { dg-error "defined" } */
-
 #define is_Z_defined defined Z
 
+#if defined Z
+#error Z is not defined
+#endif
+
+/* The behaviour of "defined" when it comes from a macro expansion is
+   now documented.  */
+#if is_Z_defined		/* { dg-warning "macro expansion" } */
+#error Macro expanding into defined operator test 1
+#endif
+
+#define Z
+
+#if !defined Z
+#error Z is defined
+#endif
+
+#if !is_Z_defined		/* { dg-warning "macro expansion" } */
+#error Macro expanding into defined operator test 2
+#endif
+
+#undef is_Z_defined
+#undef Z
+
+/* Do all the tests over again with the () form of defined.  */
+
+/* No diagnostics, though you could argue there should be.  */
+#if defined(defined)
+#error defined is defined!
+#endif
+
+#define is_Z_defined defined ( Z )
+
+#if defined(Z)
+#error Z is not defined
+#endif
+
 /* The behaviour of "defined" when it comes from a macro expansion is
    now documented.  */
 #if is_Z_defined		/* { dg-warning "macro expansion" } */
@@ -22,6 +58,11 @@
 #endif
 
 #define Z
+
+#if !defined(Z)
+#error Z is defined
+#endif
+
 #if !is_Z_defined		/* { dg-warning "macro expansion" } */
 #error Macro expanding into defined operator test 2
 #endif
===================================================================
Index: testsuite/gcc.dg/cpp/tr-defined.c
--- testsuite/gcc.dg/cpp/tr-defined.c	Tue May  5 13:32:27 1998
+++ testsuite/gcc.dg/cpp/tr-defined.c	Mon Dec 11 14:23:13 2000
@@ -0,0 +1,70 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.  */
+
+/* { dg-do preprocess } */
+/* { dg-options "-traditional" } */
+
+/* The defined operator in traditional C works just the same as the
+   defined operator in Standard C.  */
+
+/*  Source: Neil Booth, 29 Oct 2000.  */
+
+#define defined			/* { dg-error "defined" } */
+
+/* No diagnostics, though you could argue there should be.  */
+#if defined defined
+#error defined is defined!
+#endif
+
+#define is_Z_defined defined Z
+
+#if defined Z
+#error Z is not defined
+#endif
+
+/* The behaviour of "defined" when it comes from a macro expansion is
+   now documented.  */
+#if is_Z_defined
+#error Macro expanding into defined operator test 1
+#endif
+
+#define Z
+
+#if !defined Z
+#error Z is defined
+#endif
+
+#if !is_Z_defined
+#error Macro expanding into defined operator test 2
+#endif
+
+#undef is_Z_defined
+#undef Z
+
+/* Do all the tests over again with the () form of defined.  */
+
+/* No diagnostics, though you could argue there should be.  */
+#if defined(defined)
+#error defined is defined!
+#endif
+
+#define is_Z_defined defined ( Z )
+
+#if defined(Z)
+#error Z is not defined
+#endif
+
+/* The behaviour of "defined" when it comes from a macro expansion is
+   now documented.  */
+#if is_Z_defined
+#error Macro expanding into defined operator test 1
+#endif
+
+#define Z
+
+#if !defined(Z)
+#error Z is defined
+#endif
+
+#if !is_Z_defined
+#error Macro expanding into defined operator test 2
+#endif

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