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]

[C PATCH] Fix asm parsing error recovery (PR c/37772)


Hi!

When asm ( isn't followed by a string literal (nor a wide string),
the C parser crashes when trying to build_asm_expr with NULL str.  The C++
FE handles this gracefully.

Fixed thusly, bootstrapped/regtested on x86_64-linux, ok for trunk/4.4?

2009-04-01  Jakub Jelinek  <jakub@redhat.com>

	PR c/37772
	* c-parser.c (c_parser_asm_statement): Skip until close paren and
	return if c_parser_asm_string_literal returned NULL.

	* gcc.dg/pr37772.c: New test.
	* g++.dg/ext/asm11.C: New test.

--- gcc/c-parser.c.jj	2009-03-30 12:46:02.000000000 +0200
+++ gcc/c-parser.c	2009-04-01 09:43:10.000000000 +0200
@@ -4193,6 +4193,12 @@ c_parser_asm_statement (c_parser *parser
       return NULL_TREE;
     }
   str = c_parser_asm_string_literal (parser);
+  if (str == NULL_TREE)
+    {
+      parser->lex_untranslated_string = false;
+      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
+      return NULL_TREE;
+    }
   if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
     {
       simple = true;
--- gcc/testsuite/gcc.dg/pr37772.c.jj	2009-04-01 09:54:29.000000000 +0200
+++ gcc/testsuite/gcc.dg/pr37772.c	2009-04-01 09:58:32.000000000 +0200
@@ -0,0 +1,20 @@
+/* PR c/37772 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void
+foo ()
+{
+  int i;
+  asm ();		  /* { dg-error "expected string literal before" } */
+  asm (1);		  /* { dg-error "expected string literal before" } */
+  asm (int);		  /* { dg-error "expected string literal before" } */
+  asm (: "=r" (i));	  /* { dg-error "expected string literal before" } */
+  asm (1 : "=r" (i));	  /* { dg-error "expected string literal before" } */
+  asm (int : "=r" (i));	  /* { dg-error "expected string literal before" } */
+  asm (: : "r" (i));	  /* { dg-error "expected string literal before" } */
+  asm (1 : : "r" (i));	  /* { dg-error "expected string literal before" } */
+  asm (int : : "r" (i));  /* { dg-error "expected string literal before" } */
+  asm (: : : "memory");	  /* { dg-error "expected string literal before" } */
+  asm (1 : : : "memory"); /* { dg-error "expected string literal before" } */
+}
--- gcc/testsuite/g++.dg/ext/asm11.C.jj	2009-04-01 09:55:53.000000000 +0200
+++ gcc/testsuite/g++.dg/ext/asm11.C	2009-04-01 09:59:12.000000000 +0200
@@ -0,0 +1,20 @@
+// PR c/37772
+// { dg-do compile }
+// { dg-options "" }
+
+void
+foo ()
+{
+  int i;
+  asm ();		  // { dg-error "expected string-literal before" }
+  asm (1);		  // { dg-error "expected string-literal before" }
+  asm (int);		  // { dg-error "expected string-literal before" }
+  asm (: "=r" (i));	  // { dg-error "expected string-literal before" }
+  asm (1 : "=r" (i));	  // { dg-error "expected string-literal before" }
+  asm (int : "=r" (i));	  // { dg-error "expected string-literal before" }
+  asm (: : "r" (i));	  // { dg-error "expected string-literal before" }
+  asm (1 : : "r" (i));	  // { dg-error "expected string-literal before" }
+  asm (int : : "r" (i));  // { dg-error "expected string-literal before" }
+  asm (: : : "memory");	  // { dg-error "expected string-literal before" }
+  asm (1 : : : "memory"); // { dg-error "expected string-literal before" }
+}

	Jakub


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