diff mbox

[3/5,GIMPLE,FE] PR testsuite/80580. Handle invalid unary "*" operand type

Message ID b1140efc-90d1-aa20-162f-99352291080f@gmail.com
State New
Headers show

Commit Message

Mikhail Maltsev May 1, 2017, 6:07 p.m. UTC
This is essentially the same problem as in patch 2, but with unary '*'. We
should verify that its argument is a pointer.

Comments

Richard Biener May 3, 2017, 11:18 a.m. UTC | #1
On Mon, May 1, 2017 at 8:07 PM, Mikhail Maltsev <maltsevm@gmail.com> wrote:
> This is essentially the same problem as in patch 2, but with unary '*'. We
> should verify that its argument is a pointer.

This is ok with being more specific like

 "expected pointer as argument of unary %<*%>"

Thanks,
Richard.

> --
> Regards,
>    Mikhail Maltsev
>
>
> gcc/c/ChangeLog:
>
> 2017-05-01  Mikhail Maltsev  <maltsevm@gmail.com>
>
>         * gimple-parser.c (c_parser_gimple_unary_expression): Check argument
>         type of unary '*'.
>
> gcc/testsuite/ChangeLog:
>
> 2017-05-01  Mikhail Maltsev  <maltsevm@gmail.com>
>
>         * gcc.dg/gimplefe-error-8.c: New test.
>
>
diff mbox

Patch

diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c
index 2e11567..5249e8a 100644
--- a/gcc/c/gimple-parser.c
+++ b/gcc/c/gimple-parser.c
@@ -567,6 +567,11 @@  c_parser_gimple_unary_expression (c_parser *parser)
 	op = c_parser_gimple_postfix_expression (parser);
 	if (op.value == error_mark_node)
 	  return ret;
+	if (! POINTER_TYPE_P (TREE_TYPE (op.value)))
+	  {
+	    error_at (op_loc, "invalid type argument of unary %<*%>");
+	    return ret;
+	  }
 	finish = op.get_finish ();
 	location_t combined_loc = make_location (op_loc, op_loc, finish);
 	ret.value = build_simple_mem_ref_loc (combined_loc, op.value);
diff --git a/gcc/testsuite/gcc.dg/gimplefe-error-8.c b/gcc/testsuite/gcc.dg/gimplefe-error-8.c
new file mode 100644
index 0000000..faf699d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gimplefe-error-8.c
@@ -0,0 +1,7 @@ 
+/* { dg-do compile } */
+/* { dg-options "-fgimple" } */
+
+__GIMPLE() void a()
+{
+  *0 = 1; /* { dg-error "invalid type" } */
+}