diff mbox

[gimplefe] reject invalid pass name in startwith

Message ID CAAgBjMm38GXSX9vx3woUg91qrVLHh9ZLZ+jfrJ5V7+UiLMLacw@mail.gmail.com
State New
Headers show

Commit Message

Prathamesh Kulkarni Dec. 18, 2016, 12:51 p.m. UTC
On 18 December 2016 at 18:02, Jakub Jelinek <jakub@redhat.com> wrote:
> On Sun, Dec 18, 2016 at 05:41:23PM +0530, Prathamesh Kulkarni wrote:

>> --- a/gcc/c/gimple-parser.c

>> +++ b/gcc/c/gimple-parser.c

>> @@ -1046,6 +1046,17 @@ c_parser_gimple_pass_list (c_parser *parser)

>>    if (! c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))

>>      return NULL;

>>

>> +  if (pass)

>> +    {

>> +      char *full_passname = (char *) xmalloc (strlen ("tree-") + strlen (pass) + 1);

>> +      strcpy (full_passname, "tree-");

>> +      strcat (full_passname, pass);

>

> Use

>       char *full_passname = concat ("tree-", pass, NULL);

> instead?

Thanks! Modified the patch to use concat().

Regards,
Prathamesh
>

>         Jakub
2016-12-18  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>

c/
	* gimple-parser.c (c_parser_gimple_pass_list): Reject invalid pass
	name.

testsuite/
	* gcc.dg/gimplefe-19.c: New test-case.

Comments

Joseph Myers Dec. 19, 2016, 6:47 p.m. UTC | #1
The message passed to error_at should not end in \n; the diagnostics 
machinery deals with inserting the newline.

-- 
Joseph S. Myers
joseph@codesourcery.com
diff mbox

Patch

diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c
index ddecaec..68d2d74 100644
--- a/gcc/c/gimple-parser.c
+++ b/gcc/c/gimple-parser.c
@@ -1046,6 +1046,15 @@  c_parser_gimple_pass_list (c_parser *parser)
   if (! c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
     return NULL;
 
+  if (pass)
+    {
+      char *full_passname = concat ("tree-", pass, NULL);
+      opt_pass *p = g->get_passes ()->get_pass_by_name (full_passname);
+      if (!p || p->type != GIMPLE_PASS)
+	error_at (c_parser_peek_token (parser)->location,
+		  "%s is not a valid GIMPLE pass\n", pass);
+      free (full_passname);
+    }
   return pass;
 }
 
diff --git a/gcc/testsuite/gcc.dg/gimplefe-19.c b/gcc/testsuite/gcc.dg/gimplefe-19.c
new file mode 100644
index 0000000..bb5be33
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gimplefe-19.c
@@ -0,0 +1,7 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O -fgimple" } */
+
+void __GIMPLE (startwith ("combine")) foo ()  /* { dg-error "not a valid GIMPLE pass" } */
+{
+  return;
+}