Hi,
For the following test-case:

int __GIMPLE () foo (int a)
{
  return t0_1(D);
}

The compiler emits the undeclared diagnostic and then ICE's in
c_parser_gimple_postfix_expression because we don't check if
c_parser_parse_ssa_name returned error_mark_node.
ICE: https://gist.github.com/anonymous/45a01338d80faf4f21330bc9ee97ca5f

For this test-case:
int __GIMPLE() foo(int a)
{
  int _1;
  return _1(D);
}

c_parser_gimple_postfix_expression calls set_ssa_default_def which
crashes with segfault
because SSA_VAR_P(_1) is NULL and set_ssa_default_def expects it to be non-null.
ICE: https://gist.github.com/anonymous/1df5a4e8a59eca289e214bbaf07a461a

The patch rejects the above test-case with:
foo.c: In function ‘foo’:
foo.c:4:10: error: anonymous SSA name cannot have default definition
   return _1(D);

OK to commit after bootstrap+test ?

Thanks,
Prathamesh
diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c
index d959877..e1535a3 100644
--- a/gcc/c/gimple-parser.c
+++ b/gcc/c/gimple-parser.c
@@ -864,6 +864,8 @@ c_parser_gimple_postfix_expression (c_parser *parser)
              c_parser_consume_token (parser);
              expr.value = c_parser_parse_ssa_name (parser, id, NULL_TREE,
                                                    version, ver_offset);
+             if (expr.value == error_mark_node)
+               return expr;
              set_c_expr_source_range (&expr, tok_range);
              /* For default definition SSA names.  */
              if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
@@ -878,6 +880,13 @@ c_parser_gimple_postfix_expression (c_parser *parser)
                  c_parser_consume_token (parser);
                  if (! SSA_NAME_IS_DEFAULT_DEF (expr.value))
                    {
+                     if (!SSA_NAME_VAR (expr.value))
+                       {
+                         error_at (loc, "anonymous SSA name cannot have"
+                                   " default definition");
+                         expr.value = error_mark_node;
+                         return expr;
+                       }
                      set_ssa_default_def (cfun, SSA_NAME_VAR (expr.value),
                                           expr.value);
                      SSA_NAME_DEF_STMT (expr.value) = gimple_build_nop ();

Reply via email to