[2/5,GIMPLE,FE] PR testsuite/80580: handle invalid types of "->" operands
diff mbox

Message ID CAFiYyc1sdO8ya2wi11KDntdCx39BUMpXe5E9n1W-7OvVge=AFg@mail.gmail.com
State New
Headers show

Commit Message

Richard Biener May 3, 2017, 11:16 a.m. UTC
On Mon, May 1, 2017 at 8:05 PM, Mikhail Maltsev <maltsevm@gmail.com> wrote:
> This bug happens when the LHS of operator '->' is either missing, i.e.:
>
> (->a) = 0;
>
> or it is not a pointer:
>
> int b;
> b_2->c = 0;
>
> LHS should be validated.

I think for the missing LHS it's better to simply not generate code
when expr is in error
state like with


it'll also get us some error recovery compared to stop parsing earlier.

So maybe you can factor out the "missing op" case from this and the
DOT case, doing
the above?

Then handle callers of build_simple_mem_ref_loc to add sanity checking
that we've
dereferencing a pointer.

Thanks,
Richard.

> --
> Regards,
>    Mikhail Maltsev
>
> gcc/testsuite/ChangeLog:
>
> 2017-05-01  Mikhail Maltsev  <maltsevm@gmail.com>
>
>         * gcc.dg/gimplefe-error-6.c: New test.
>         * gcc.dg/gimplefe-error-7.c: New test.
>
>
> gcc/c/ChangeLog:
>
> 2017-05-01  Mikhail Maltsev  <maltsevm@gmail.com>
>
>         * gimple-parser.c (c_parser_gimple_postfix_expression_after_primary):
>         Check LHS of operator '->'
>
>

Patch
diff mbox

Index: gcc/c/gimple-parser.c
===================================================================
--- gcc/c/gimple-parser.c       (revision 247542)
+++ gcc/c/gimple-parser.c       (working copy)
@@ -968,6 +968,8 @@  c_parser_gimple_postfix_expression_after
                break;
              }

+           if (expr.value == error_mark_node)
+             break;
            start = expr.get_start ();
            finish = c_parser_tokens_buf (parser, 0)->location;
            expr.value = build_array_ref (op_loc, expr.value, idx);
@@ -986,6 +988,8 @@  c_parser_gimple_postfix_expression_after
              c_parser_gimple_expr_list (parser, &exprlist);
            c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
                                       "expected %<)%>");
+           if (expr.value == error_mark_node)
+             break;
            expr.value = build_call_array_loc
                (expr_loc, TREE_TYPE (TREE_TYPE (expr.value)),
                 expr.value, exprlist.length (), exprlist.address ());
@@ -1014,6 +1018,8 @@  c_parser_gimple_postfix_expression_after
            start = expr.get_start ();
            finish = c_parser_peek_token (parser)->get_finish ();
            c_parser_consume_token (parser);
+           if (expr.value == error_mark_node)
+             break;
            expr.value = build_component_ref (op_loc, expr.value, ident,
                                              comp_loc);
            set_c_expr_source_range (&expr, start, finish);
@@ -1052,6 +1058,8 @@  c_parser_gimple_postfix_expression_after
            start = expr.get_start ();
            finish = c_parser_peek_token (parser)->get_finish ();
            c_parser_consume_token (parser);
+           if (expr.value == error_mark_node)
+             break;
            expr.value = build_component_ref (op_loc,
                                              build_simple_mem_ref_loc
                                                (op_loc, expr.value),