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: FYI: fix PR preprocessor/30786


I'm checking this in.

This fixes PR preprocessor/30786.  The bug here is an ICE if "_Pragma"
appears at EOF.

Bootstrapped and regtested on x86 FC-6.  New test case included.

Tom

libcpp/ChangeLog:
2007-10-31  Tom Tromey  <tromey@redhat.com>

	PR preprocessor/30786:
	* macro.c (builtin_macro): Return result of _cpp_do__Pragma.
	* directives.c (_cpp_do__Pragma): Return error status.
	* internal.h (_cpp_do__Pragma): Update.
	* directives.c (get__Pragma_string): Back up if EOF seen.

gcc/testsuite/ChangeLog:
2007-10-31  Tom Tromey  <tromey@redhat.com>

	PR preprocessor/30786:
	* gcc.dg/cpp/pr30786.c: New file.

Index: libcpp/directives.c
===================================================================
--- libcpp/directives.c	(revision 129492)
+++ libcpp/directives.c	(working copy)
@@ -1467,15 +1467,24 @@
 get__Pragma_string (cpp_reader *pfile)
 {
   const cpp_token *string;
+  const cpp_token *paren;
 
-  if (get_token_no_padding (pfile)->type != CPP_OPEN_PAREN)
+  paren = get_token_no_padding (pfile);
+  if (paren->type == CPP_EOF)
+    _cpp_backup_tokens (pfile, 1);
+  if (paren->type != CPP_OPEN_PAREN)
     return NULL;
 
   string = get_token_no_padding (pfile);
+  if (string->type == CPP_EOF)
+    _cpp_backup_tokens (pfile, 1);
   if (string->type != CPP_STRING && string->type != CPP_WSTRING)
     return NULL;
 
-  if (get_token_no_padding (pfile)->type != CPP_CLOSE_PAREN)
+  paren = get_token_no_padding (pfile);
+  if (paren->type == CPP_EOF)
+    _cpp_backup_tokens (pfile, 1);
+  if (paren->type != CPP_CLOSE_PAREN)
     return NULL;
 
   return string;
@@ -1595,18 +1604,21 @@
   _cpp_push_token_context (pfile, NULL, toks, count);
 }
 
-/* Handle the _Pragma operator.  */
-void
+/* Handle the _Pragma operator.  Return 0 on error, 1 if ok.  */
+int
 _cpp_do__Pragma (cpp_reader *pfile)
 {
   const cpp_token *string = get__Pragma_string (pfile);
   pfile->directive_result.type = CPP_PADDING;
 
   if (string)
-    destringize_and_run (pfile, &string->val.str);
-  else
-    cpp_error (pfile, CPP_DL_ERROR,
-	       "_Pragma takes a parenthesized string literal");
+    {
+      destringize_and_run (pfile, &string->val.str);
+      return 1;
+    }
+  cpp_error (pfile, CPP_DL_ERROR,
+	     "_Pragma takes a parenthesized string literal");
+  return 0;
 }
 
 /* Handle #ifdef.  */
Index: libcpp/macro.c
===================================================================
--- libcpp/macro.c	(revision 129492)
+++ libcpp/macro.c	(working copy)
@@ -300,8 +300,7 @@
       if (pfile->state.in_directive)
 	return 0;
 
-      _cpp_do__Pragma (pfile);
-      return 1;
+      return _cpp_do__Pragma (pfile);
     }
 
   buf = _cpp_builtin_macro_text (pfile, node);
Index: libcpp/internal.h
===================================================================
--- libcpp/internal.h	(revision 129492)
+++ libcpp/internal.h	(working copy)
@@ -576,7 +576,7 @@
 extern void _cpp_define_builtin (cpp_reader *, const char *);
 extern char ** _cpp_save_pragma_names (cpp_reader *);
 extern void _cpp_restore_pragma_names (cpp_reader *, char **);
-extern void _cpp_do__Pragma (cpp_reader *);
+extern int _cpp_do__Pragma (cpp_reader *);
 extern void _cpp_init_directives (cpp_reader *);
 extern void _cpp_init_internal_pragmas (cpp_reader *);
 extern void _cpp_do_file_change (cpp_reader *, enum lc_reason, const char *,
Index: gcc/testsuite/gcc.dg/cpp/pr30786.c
===================================================================
--- gcc/testsuite/gcc.dg/cpp/pr30786.c	(revision 0)
+++ gcc/testsuite/gcc.dg/cpp/pr30786.c	(revision 0)
@@ -0,0 +1,9 @@
+/* PR preprocessor/30786 - _Pragma at end of file should not ICE */
+/* { dg-do compile } */
+
+/* { dg-error "parenthesized" "" { target *-*-* } 9 } */
+/* { dg-error "expected" "" { target *-*-* } 9 } */
+
+int x;
+
+_Pragma


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