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]
Other format: [Raw text]

Fix 3 CPP PRs


2 tradcpp bugs, and we didn't call the #undef handler for non-macros.

Neil.

	* cpplib.c (prepare_directive_trad): Clear skipping only in
	#if and #elif directives.
	(do_undef): Call the handler even if the identifier is not a macro.
	* cpptrad.c (scan_parameters): Emit an error message.
	(_cpp_create_trad_definition): Remember the params list even on
	failure.
	* testsuite/gcc.dg/cpp/trad/macro.c: New tests.

Index: cpplib.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.c,v
retrieving revision 1.354
diff -u -p -r1.354 cpplib.c
--- cpplib.c	1 Nov 2003 22:56:51 -0000	1.354
+++ cpplib.c	12 Dec 2003 06:50:10 -0000
@@ -272,14 +272,17 @@ prepare_directive_trad (cpp_reader *pfil
 			&& ! (pfile->directive->flags & EXPAND));
       bool was_skipping = pfile->state.skipping;
 
-      pfile->state.skipping = false;
       pfile->state.in_expression = (pfile->directive == &dtable[T_IF]
 				    || pfile->directive == &dtable[T_ELIF]);
+      if (pfile->state.in_expression)
+	pfile->state.skipping = false;
+
       if (no_expand)
 	pfile->state.prevent_expansion++;
       _cpp_scan_out_logical_line (pfile, NULL);
       if (no_expand)
 	pfile->state.prevent_expansion--;
+
       pfile->state.skipping = was_skipping;
       _cpp_overlay_buffer (pfile, pfile->out.base,
 			   pfile->out.cur - pfile->out.base);
@@ -520,22 +523,26 @@ do_undef (cpp_reader *pfile)
 {
   cpp_hashnode *node = lex_macro_node (pfile);
 
-  /* 6.10.3.5 paragraph 2: [#undef] is ignored if the specified identifier
-     is not currently defined as a macro name.  */
-  if (node && node->type == NT_MACRO)
+  if (node)
     {
       if (pfile->cb.undef)
 	pfile->cb.undef (pfile, pfile->directive_line, node);
 
-      if (node->flags & NODE_WARN)
-	cpp_error (pfile, CPP_DL_WARNING,
-		   "undefining \"%s\"", NODE_NAME (node));
+      /* 6.10.3.5 paragraph 2: [#undef] is ignored if the specified
+	 identifier is not currently defined as a macro name.  */
+      if (node->type == NT_MACRO)
+	{
+	  if (node->flags & NODE_WARN)
+	    cpp_error (pfile, CPP_DL_WARNING,
+		       "undefining \"%s\"", NODE_NAME (node));
 
-      if (CPP_OPTION (pfile, warn_unused_macros))
-	_cpp_warn_if_unused_macro (pfile, node, NULL);
+	  if (CPP_OPTION (pfile, warn_unused_macros))
+	    _cpp_warn_if_unused_macro (pfile, node, NULL);
 
-      _cpp_free_definition (node);
+	  _cpp_free_definition (node);
+	}
     }
+
   check_eol (pfile);
 }
 
Index: cpptrad.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpptrad.c,v
retrieving revision 1.39
diff -u -p -r1.39 cpptrad.c
--- cpptrad.c	19 Nov 2003 18:48:24 -0000	1.39
+++ cpptrad.c	12 Dec 2003 06:50:10 -0000
@@ -907,6 +907,9 @@ scan_parameters (cpp_reader *pfile, cpp_
       break;
     }
 
+  if (!ok)
+    cpp_error (pfile, CPP_DL_ERROR, "syntax error in macro parameter list");
+
   CUR (pfile->context) = cur + (*cur == ')');
 
   return ok;
@@ -982,14 +985,17 @@ _cpp_create_trad_definition (cpp_reader 
   /* Is this a function-like macro?  */
   if (* CUR (context) == '(')
     {
+      bool ok = scan_parameters (pfile, macro);
+
+      /* Remember the params so we can clear NODE_MACRO_ARG flags.  */
+      macro->params = (cpp_hashnode **) BUFF_FRONT (pfile->a_buff);
+
       /* Setting macro to NULL indicates an error occurred, and
 	 prevents unnecessary work in _cpp_scan_out_logical_line.  */
-      if (!scan_parameters (pfile, macro))
+      if (!ok)
 	macro = NULL;
       else
 	{
-	  /* Success.  Commit the parameter array.  */
-	  macro->params = (cpp_hashnode **) BUFF_FRONT (pfile->a_buff);
 	  BUFF_FRONT (pfile->a_buff) = (uchar *) &macro->params[macro->paramc];
 	  macro->fun_like = 1;
 	}
Index: testsuite/gcc.dg/cpp/trad/macro.c
===================================================================
RCS file: testsuite/gcc.dg/cpp/trad/macro.c
diff -N testsuite/gcc.dg/cpp/trad/macro.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.dg/cpp/trad/macro.c	12 Dec 2003 06:50:14 -0000
@@ -0,0 +1,11 @@
+/* Test that varargs are rejected, and that we don't complain about
+   macro args in skipped blocks.  */
+
+/* { dg-do preprocess } */
+
+#define f(x) 
+#define g(x, y...)		/* { dg-error "macro parameter list" } */
+
+#if 0
+#define f(a,b)			/* { dg-bogus "passed 2 arguments" } */
+#endif


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