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]

Fix -traditional directive handling


I'm not sure if this has already been posted or not.  In -traditional
mode, directives are only to be recognized if the # is in column 1.
The bug was found by Jakub Jelinek.

zw

	* tradcpp.c (rescan): Do not recognize directives when the #
	is indented.

	* gcc.dg/cpp/tr-direct.c: New test.

===================================================================
Index: tradcpp.c
--- tradcpp.c	2000/07/13 04:43:47	1.5
+++ tradcpp.c	2000/07/19 20:32:30
@@ -1187,32 +1187,11 @@ do { ip = &instack[indepth];		\
       if (ident_length)
 	goto specialchar;
 
-      /* # keyword: a # must be first nonblank char on the line */
+      /* # keyword: a # must be the first char on the line */
       if (beg_of_line == 0)
 	goto randomchar;
-      {
-	U_CHAR *bp;
-
-	/* Scan from start of line, skipping whitespace, comments
-	   and backslash-newlines, and see if we reach this #.
-	   If not, this # is not special.  */
-	bp = beg_of_line;
-	while (1) {
-	  if (is_hor_space[*bp])
-	    bp++;
-	  else if (*bp == '\\' && bp[1] == '\n')
-	    bp += 2;
-	  else if (*bp == '/' && (newline_fix (bp + 1), bp[1]) == '*') {
-	    bp += 2;
-	    while (!(*bp == '*' && (newline_fix (bp + 1), bp[1]) == '/'))
-	      bp++;
-	    bp += 1;
-	  }
-	  else break;
-	}
-	if (bp + 1 != ibp)
-	  goto randomchar;
-      }
+      if (beg_of_line + 1 != ibp)
+	goto randomchar;
 
       /* This # can start a directive.  */
 
===================================================================
Index: testsuite/gcc.dg/cpp/tr-direct.c
--- testsuite/gcc.dg/cpp/tr-direct.c	Tue May  5 13:32:27 1998
+++ testsuite/gcc.dg/cpp/tr-direct.c	Wed Jul 19 13:32:36 2000
@@ -0,0 +1,11 @@
+/* Test for some basic aspects of -traditional directive processing.  */
+
+/* { dg-do preprocess } */
+/* { dg-options -traditional } */
+
+/* There is no #error directive.  */
+
+#error bad	/* { dg-bogus "bad" } */
+
+/* Directives with their #s indented are not recognized.  */
+ #if 0	/* { dg-bogus "unterminated" } */

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