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]

[PATCH][match-and-simplify] Fail more gracefully when encountering EOF


This fixes the segfaults when an unexpected EOF occurs.

Committed.

Richard.

2014-08-27  Richard Biener  <rguenther@suse.de>

	* genmatch.c (peek): Fail at unexpected EOF.
	(main): Do not peek at the next token as we do expect
	EOF at some point.

Index: gcc/genmatch.c
===================================================================
--- gcc/genmatch.c	(revision 214567)
+++ gcc/genmatch.c	(working copy)
@@ -2005,6 +2005,11 @@ peek (cpp_reader *r)
     }
   while (token->type == CPP_PADDING
 	 && token->type != CPP_EOF);
+  /* If we peek at EOF this is a fatal error as it leaves the
+     cpp_reader in unusable state.  Assume we really wanted a
+     token and thus this EOF is unexpected.  */
+  if (token->type == CPP_EOF)
+    fatal_at (token, "unexpected end of file");
   return token;
 }
 
@@ -2553,8 +2558,13 @@ add_operator (CONVERT2, "CONVERT2", "tcc
 
   vec<simplify *> simplifiers = vNULL;
 
-  while (peek (r)->type != CPP_EOF)
-    parse_pattern (r, simplifiers);
+  const cpp_token *token = next (r);
+  while (token->type != CPP_EOF)
+    {
+      _cpp_backup_tokens (r, 1);
+      parse_pattern (r, simplifiers);
+      token = next (r);
+    }
 
   for (unsigned i = 0; i < simplifiers.length (); ++i)
     check_no_user_id (simplifiers[i]);


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