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: preprocessor/538: cpp0 loops while expanding macros


Thanks for the bug report and a nice test case.  They should lock you
up for extreme preprocessor abuse and writing incomprehensible macros
:)

Testcase simplified and fixed thusly.

Bootstrapping and running testsuite.  Assuming these succeed, OK to
commit?

Neil.

	* cpplex.c (push_macro_context): Set an argument's level after
	calling parse_args.  We could loop infinitely otherwise.
	* gcc.dg/cpp/macro2.c: New testcase.

Index: cpplex.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cpplex.c,v
retrieving revision 1.96
diff -u -p -r1.96 cpplex.c
--- cpplex.c	2000/09/15 05:55:36	1.96
+++ cpplex.c	2000/09/15 17:38:10
@@ -2972,7 +2972,6 @@ push_macro_context (pfile, token)
       args->tokens = 0;
       args->capacity = 0;
       args->used = 0;
-      args->level = pfile->cur_context;
 
       prev_nme = prevent_macro_expansion (pfile);
       pfile->args = args;
@@ -2984,6 +2983,8 @@ push_macro_context (pfile, token)
 	  free_macro_args (args);
 	  return 1;
 	}
+      /* Set the level after the call to parse_args.  */
+      args->level = pfile->cur_context;
     }
 
   /* Now push its context.  */
Index: testsuite/gcc.dg/cpp/macro2.c
===================================================================
RCS file: macro2.c
diff -N macro2.c
--- /dev/null	Tue May  5 13:32:27 1998
+++ macro2.c	Fri Sep 15 10:38:30 2000
@@ -0,0 +1,14 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.  */
+
+/* { dg-do preprocess } */
+
+/* Tests the argument context get set at the lower level if we drop
+   contexts whilst parsing arguments.  This would enter an infinite
+   loop in is_macro_disabled previously.  */
+
+#define A Something
+#define B C
+#define C K(
+#define K(S) S  
+#define T B A )
+T				/* Expands to <Something>.  */


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