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]

Patch for over-eager multiple include optimization


Recent changes to the way #if worked were causing cpp to think a file
didn't need to be reread, when in fact it did.  This fixes that.

The test case is gcc.dg/cpp-mi2.c and cpp-mi2[abc].h.

zw

	* cpplib.c (do_elif): Skip the rest of the line if we're
	not going to bother evaluating it.
	(skip_if_group): Clear pfile->only_seen_white.  Reorder loop
	to avoid pointless calls to the lexer.

===================================================================
Index: cpplib.c
--- cpplib.c	2000/04/06 07:56:14	1.141
+++ cpplib.c	2000/04/07 21:06:00
@@ -1266,7 +1266,10 @@ do_elif (pfile)
     }
 
   if (pfile->if_stack->if_succeeded)
-    return skip_if_group (pfile);
+    {
+      _cpp_skip_rest_of_line (pfile);
+      return skip_if_group (pfile);
+    }
   if (_cpp_parse_expr (pfile) == 0)
     return skip_if_group (pfile);
 
@@ -1498,11 +1501,24 @@ skip_if_group (pfile)
   long old_written;
   int ret = 0;
 
+  /* We are no longer at the start of the file.  */
+  pfile->only_seen_white = 0;
+
   old_written = CPP_WRITTEN (pfile);
   pfile->no_macro_expand++;
   CPP_OPTION (pfile, no_line_commands)++;
   for (;;)
     {
+      /* We are at the end of a line.  Only cpp_get_token knows how to
+	 advance the line number correctly.  */
+      token = cpp_get_token (pfile);
+      if (token == CPP_POP)
+	break;  /* Caller will issue error.  */
+      
+      else if (token != CPP_VSPACE)
+	cpp_ice (pfile, "cpp_get_token returned %d in skip_if_group", token);
+      CPP_SET_WRITTEN (pfile, old_written);
+
       token = _cpp_get_directive_token (pfile);
 
       if (token == CPP_DIRECTIVE)
@@ -1514,16 +1530,6 @@ skip_if_group (pfile)
 
       if (token != CPP_VSPACE)
 	_cpp_skip_rest_of_line (pfile);
-
-      /* Only cpp_get_token knows how to advance the line number
-	 properly.  */
-      token = cpp_get_token (pfile);
-      if (token == CPP_POP)
-	break;  /* Caller will issue error.  */
-      
-      else if (token != CPP_VSPACE)
-	cpp_ice (pfile, "cpp_get_token returned %d in skip_if_group", token);
-      CPP_SET_WRITTEN (pfile, old_written);
     }
   CPP_SET_WRITTEN (pfile, old_written);
   pfile->no_macro_expand--;

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