public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][GIMPLEFE] Fix for ICE due to undeclared variable
@ 2016-12-28 18:39 Prasad Ghangal
  2016-12-28 19:16 ` Prasad Ghangal
  2017-01-04 10:32 ` Richard Biener
  0 siblings, 2 replies; 7+ messages in thread
From: Prasad Ghangal @ 2016-12-28 18:39 UTC (permalink / raw)
  To: GCC Patches, Richard Biener

[-- Attachment #1: Type: text/plain, Size: 171 bytes --]

Hi,
The attached patch tries fix ICE due to undeclared variable(s) in the input.
Successfully bootstrapped on x86_64-pc-linux-gnu, testing is in progress


Thanks,
Prasad

[-- Attachment #2: Changelog --]
[-- Type: application/octet-stream, Size: 546 bytes --]

diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 7a5e741..1cbf5be 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,11 @@
+2016-12-28  Prasad Ghangal  <prasad.ghangal@gmail.com>
+
+	* gimple-parser.c (c_parser_gimple_binary_expression): Check
+	lhs.value and rhs.value before calling build2loc.
+	(c_parser_parse_ssa_name): Check if parent is valid.
+	(c_parser_gimple_if_stmt): Return if cond is error_mark_node.
+	(c_parser_gimple_switch_stmt): Likewise.
+
 2016-12-21  Jakub Jelinek  <jakub@redhat.com>
 
 	PR bootstrap/78817


[-- Attachment #3: undecl_var.patch --]
[-- Type: text/x-patch, Size: 2414 bytes --]

diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c
index b7cef93..13bf2b1 100644
--- a/gcc/c/gimple-parser.c
+++ b/gcc/c/gimple-parser.c
@@ -516,7 +516,9 @@ c_parser_gimple_binary_expression (c_parser *parser)
   rhs = c_parser_gimple_postfix_expression (parser);
   if (c_parser_error (parser))
     return ret;
-  ret.value = build2_loc (ret_loc, code, ret_type, lhs.value, rhs.value);
+
+  if (lhs.value != error_mark_node && rhs.value != error_mark_node)
+    ret.value = build2_loc (ret_loc, code, ret_type, lhs.value, rhs.value);
   return ret;
 }
 
@@ -653,7 +655,7 @@ c_parser_parse_ssa_name (c_parser *parser,
 	  id = get_identifier (var_name);
 	  tree parent = lookup_name (id);
 	  XDELETEVEC (var_name);
-	  if (! parent)
+	  if (! parent || parent == error_mark_node)
 	    {
 	      c_parser_error (parser, "base variable or SSA name not declared"); 
 	      return error_mark_node;
@@ -1194,6 +1196,8 @@ c_parser_gimple_if_stmt (c_parser *parser, gimple_seq *seq)
   location_t loc;
   c_parser_consume_token (parser);
   tree cond = c_parser_gimple_paren_condition (parser);
+  if (cond == error_mark_node)
+    return;
 
   if (c_parser_next_token_is_keyword (parser, RID_GOTO))
     {
@@ -1252,7 +1256,7 @@ c_parser_gimple_if_stmt (c_parser *parser, gimple_seq *seq)
 static void
 c_parser_gimple_switch_stmt (c_parser *parser, gimple_seq *seq)
 {
-  c_expr cond_expr;
+  tree cond = error_mark_node;
   tree case_label, label;
   auto_vec<tree> labels;
   tree default_label = NULL_TREE;
@@ -1261,9 +1265,11 @@ c_parser_gimple_switch_stmt (c_parser *parser, gimple_seq *seq)
 
   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
     {
-      cond_expr = c_parser_gimple_postfix_expression (parser);
+      cond = c_parser_gimple_postfix_expression (parser).value;
       if (! c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
 	return;
+      if (cond == error_mark_node)
+	return;
     }
 
   if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
@@ -1374,7 +1380,7 @@ c_parser_gimple_switch_stmt (c_parser *parser, gimple_seq *seq)
     }
   if (! c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>"))
     return;
-  gimple_seq_add_stmt (seq, gimple_build_switch (cond_expr.value,
+  gimple_seq_add_stmt (seq, gimple_build_switch (cond,
 						 default_label, labels));
   gimple_seq_add_seq (seq, switch_body);
   labels.release();

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH][GIMPLEFE] Fix for ICE due to undeclared variable
  2016-12-28 18:39 [PATCH][GIMPLEFE] Fix for ICE due to undeclared variable Prasad Ghangal
@ 2016-12-28 19:16 ` Prasad Ghangal
  2017-01-04 10:32 ` Richard Biener
  1 sibling, 0 replies; 7+ messages in thread
From: Prasad Ghangal @ 2016-12-28 19:16 UTC (permalink / raw)
  To: rguenther; +Cc: GCC Patches

Sorry for the wrong email address.

On 28 December 2016 at 23:57, Prasad Ghangal <prasad.ghangal@gmail.com> wrote:
> Hi,
> The attached patch tries fix ICE due to undeclared variable(s) in the input.
> Successfully bootstrapped on x86_64-pc-linux-gnu, testing is in progress
>
>
> Thanks,
> Prasad

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH][GIMPLEFE] Fix for ICE due to undeclared variable
  2016-12-28 18:39 [PATCH][GIMPLEFE] Fix for ICE due to undeclared variable Prasad Ghangal
  2016-12-28 19:16 ` Prasad Ghangal
@ 2017-01-04 10:32 ` Richard Biener
  2017-02-06  6:00   ` Prasad Ghangal
  1 sibling, 1 reply; 7+ messages in thread
From: Richard Biener @ 2017-01-04 10:32 UTC (permalink / raw)
  To: Prasad Ghangal; +Cc: GCC Patches

On Wed, Dec 28, 2016 at 7:27 PM, Prasad Ghangal
<prasad.ghangal@gmail.com> wrote:
> Hi,
> The attached patch tries fix ICE due to undeclared variable(s) in the input.
> Successfully bootstrapped on x86_64-pc-linux-gnu, testing is in progress

Ok.

Richard.

>
> Thanks,
> Prasad

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH][GIMPLEFE] Fix for ICE due to undeclared variable
  2017-01-04 10:32 ` Richard Biener
@ 2017-02-06  6:00   ` Prasad Ghangal
  2017-02-07  8:10     ` Richard Biener
  0 siblings, 1 reply; 7+ messages in thread
From: Prasad Ghangal @ 2017-02-06  6:00 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches

On 4 January 2017 at 16:02, Richard Biener <richard.guenther@gmail.com> wrote:
> On Wed, Dec 28, 2016 at 7:27 PM, Prasad Ghangal
> <prasad.ghangal@gmail.com> wrote:
>> Hi,
>> The attached patch tries fix ICE due to undeclared variable(s) in the input.
>> Successfully bootstrapped on x86_64-pc-linux-gnu, testing is in progress
>
> Ok.
>
Can you please commit the patch? I don't have access for that.

Thanks,
Prasad

> Richard.
>
>>
>> Thanks,
>> Prasad

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH][GIMPLEFE] Fix for ICE due to undeclared variable
  2017-02-06  6:00   ` Prasad Ghangal
@ 2017-02-07  8:10     ` Richard Biener
  2017-02-09  6:00       ` Prasad Ghangal
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Biener @ 2017-02-07  8:10 UTC (permalink / raw)
  To: Prasad Ghangal; +Cc: GCC Patches

On Mon, Feb 6, 2017 at 7:00 AM, Prasad Ghangal <prasad.ghangal@gmail.com> wrote:
> On 4 January 2017 at 16:02, Richard Biener <richard.guenther@gmail.com> wrote:
>> On Wed, Dec 28, 2016 at 7:27 PM, Prasad Ghangal
>> <prasad.ghangal@gmail.com> wrote:
>>> Hi,
>>> The attached patch tries fix ICE due to undeclared variable(s) in the input.
>>> Successfully bootstrapped on x86_64-pc-linux-gnu, testing is in progress
>>
>> Ok.
>>
> Can you please commit the patch? I don't have access for that.

Can you share a testcase that broke?  I tried

int __GIMPLE foo(int a)
{
  if (t1 != 2)
    goto bb1;
  else
    goto bb2;

bb1:
  return t1;

bb2:
  return 1;
}

and it reports

t.c: In function ‘foo’:
t.c:3:7: error: ‘t1’ undeclared (first use in this function)
   if (t1 != 2)
       ^~
t.c:3:7: note: each undeclared identifier is reported only once for
each function it appears in
t.c:9:10: error: invalid conversion in return statement
   return t1;
          ^~
t.c:1:14: note: declared here
 int __GIMPLE foo(int a)
              ^~~

and thus doesn't ICE.

Maybe one of my patches in this area made yours redundant (it doesn't
apply cleanly anymore as well).

Thanks,
Richard.

> Thanks,
> Prasad
>
>> Richard.
>>
>>>
>>> Thanks,
>>> Prasad

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH][GIMPLEFE] Fix for ICE due to undeclared variable
  2017-02-07  8:10     ` Richard Biener
@ 2017-02-09  6:00       ` Prasad Ghangal
  2017-02-10 12:46         ` Richard Biener
  0 siblings, 1 reply; 7+ messages in thread
From: Prasad Ghangal @ 2017-02-09  6:00 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 7138 bytes --]

On 7 February 2017 at 13:40, Richard Biener <richard.guenther@gmail.com> wrote:
> On Mon, Feb 6, 2017 at 7:00 AM, Prasad Ghangal <prasad.ghangal@gmail.com> wrote:
>> On 4 January 2017 at 16:02, Richard Biener <richard.guenther@gmail.com> wrote:
>>> On Wed, Dec 28, 2016 at 7:27 PM, Prasad Ghangal
>>> <prasad.ghangal@gmail.com> wrote:
>>>> Hi,
>>>> The attached patch tries fix ICE due to undeclared variable(s) in the input.
>>>> Successfully bootstrapped on x86_64-pc-linux-gnu, testing is in progress
>>>
>>> Ok.
>>>
>> Can you please commit the patch? I don't have access for that.
>
> Can you share a testcase that broke?  I tried
>

Consider following testcases:

Case 1:
int __GIMPLE foo()
{
  if (a != 2)
    goto bb1;
  else
    goto bb2;

bb1:
  a_1 = 10;
  return a_1;

bb2:
  return 1;
}

gives:

 foo
gcc/test.c: In function ‘foo’:
gcc/test.c:3:7: error: ‘a’ undeclared (first use in this function)
   if (a != 2)
       ^
gcc/test.c:3:7: note: each undeclared identifier is reported only once
for each function it appears in
gcc/test.c:9:3: internal compiler error: in make_ssa_name_fn, at
tree-ssanames.c:268
   a_1 = 10;
   ^~~
0x1199aa0 make_ssa_name_fn(function*, tree_node*, gimple*, unsigned int)
        ../../git_gcc/gcc/tree-ssanames.c:265
0x839e2c c_parser_parse_ssa_name
        ../../git_gcc/gcc/c/gimple-parser.c:675
0x83a5e6 c_parser_gimple_postfix_expression
        ../../git_gcc/gcc/c/gimple-parser.c:845
0x839ac5 c_parser_gimple_unary_expression
        ../../git_gcc/gcc/c/gimple-parser.c:603
0x838544 c_parser_gimple_statement
        ../../git_gcc/gcc/c/gimple-parser.c:271
0x83848e c_parser_gimple_compound_statement
        ../../git_gcc/gcc/c/gimple-parser.c:226
0x837fd2 c_parser_parse_gimple_body(c_parser*)
        ../../git_gcc/gcc/c/gimple-parser.c:92
0x7f7bb5 c_parser_declaration_or_fndef
        ../../git_gcc/gcc/c/c-parser.c:2091
0x7f628a c_parser_external_declaration
        ../../git_gcc/gcc/c/c-parser.c:1468
0x7f5dd3 c_parser_translation_unit
        ../../git_gcc/gcc/c/c-parser.c:1348
0x82a3c4 c_parse_file()
        ../../git_gcc/gcc/c/c-parser.c:18185
0x89c5d9 c_common_parse_file()
        ../../git_gcc/gcc/c-family/c-opts.c:1107
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.



Case 2:

int __GIMPLE ()
main (int argc, char * * argv)
{

  bb_2:
  switch (a) {default: L2; case 1: L0; case 2: L1; }

L0:
  a = 0;
  goto bb_6;

L1:
  a = 3;
  goto L2;

L2:
  return a;

}

 main
gcc/test3.c: In function ‘main’:
gcc/test3.c:6:11: error: ‘a’ undeclared (first use in this function)
   switch (a) {default: L2; case 1: L0; case 2: L1; }
           ^
gcc/test3.c:6:11: note: each undeclared identifier is reported only
once for each function it appears in
gcc/test3.c:6:3: internal compiler error: in gimple_switch_set_index,
at gimple.h:4513
   switch (a) {default: L2; case 1: L0; case 2: L1; }
   ^~~~~~
0xb31385 gimple_switch_set_index
        ../../git_gcc/gcc/gimple.h:4513
0xb33b3f gimple_build_switch_nlabels(unsigned int, tree_node*, tree_node*)
        ../../git_gcc/gcc/gimple.c:757
0xb33b90 gimple_build_switch(tree_node*, tree_node*, vec<tree_node*,
va_heap, vl_ptr>)
        ../../git_gcc/gcc/gimple.c:773
0x83bd94 c_parser_gimple_switch_stmt
        ../../git_gcc/gcc/c/gimple-parser.c:1445
0x83832c c_parser_gimple_compound_statement
        ../../git_gcc/gcc/c/gimple-parser.c:175
0x837fd2 c_parser_parse_gimple_body(c_parser*)
        ../../git_gcc/gcc/c/gimple-parser.c:92
0x7f7bb5 c_parser_declaration_or_fndef
        ../../git_gcc/gcc/c/c-parser.c:2091
0x7f628a c_parser_external_declaration
        ../../git_gcc/gcc/c/c-parser.c:1468
0x7f5dd3 c_parser_translation_unit
        ../../git_gcc/gcc/c/c-parser.c:1348
0x82a3c4 c_parse_file()
        ../../git_gcc/gcc/c/c-parser.c:18185
0x89c5d9 c_common_parse_file()
        ../../git_gcc/gcc/c-family/c-opts.c:1107
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.


Case 3:

void __GIMPLE () foo (int a)
{
bb_2:
  a = *b;

bb_3:
  return;
}

 foo
gcc/test6.c: In function ‘foo’:
gcc/test6.c:5:8: error: ‘b’ undeclared (first use in this function)
   a = *b;
        ^
gcc/test6.c:5:8: note: each undeclared identifier is reported only
once for each function it appears in
gcc/test6.c:5:3: internal compiler error: tree check: expected class
‘type’, have ‘exceptional’ (error_mark) in build_int_cst, at
tree.c:1297
   a = *b;
   ^
0x125cd92 tree_class_check_failed(tree_node const*, tree_code_class,
char const*, int, char const*)
        ../../git_gcc/gcc/tree.c:9866
0x77f8e3 tree_class_check(tree_node*, tree_code_class, char const*,
int, char const*)
        ../../git_gcc/gcc/tree.h:3183
0x123db1e build_int_cst(tree_node*, long)
        ../../git_gcc/gcc/tree.c:1297
0x124b279 build_simple_mem_ref_loc(unsigned int, tree_node*)
        ../../git_gcc/gcc/tree.c:4634
0x8396a8 c_parser_gimple_unary_expression
        ../../git_gcc/gcc/c/gimple-parser.c:565
0x838c9a c_parser_gimple_statement
        ../../git_gcc/gcc/c/gimple-parser.c:339
0x83848e c_parser_gimple_compound_statement
        ../../git_gcc/gcc/c/gimple-parser.c:226
0x837fd2 c_parser_parse_gimple_body(c_parser*)
        ../../git_gcc/gcc/c/gimple-parser.c:92
0x7f7bb5 c_parser_declaration_or_fndef
        ../../git_gcc/gcc/c/c-parser.c:2091
0x7f628a c_parser_external_declaration
        ../../git_gcc/gcc/c/c-parser.c:1468
0x7f5dd3 c_parser_translation_unit
        ../../git_gcc/gcc/c/c-parser.c:1348
0x82a3c4 c_parse_file()
        ../../git_gcc/gcc/c/c-parser.c:18185
0x89c5d9 c_common_parse_file()
        ../../git_gcc/gcc/c-family/c-opts.c:1107
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.


> int __GIMPLE foo(int a)
> {
>   if (t1 != 2)
>     goto bb1;
>   else
>     goto bb2;
>
> bb1:
>   return t1;
>
> bb2:
>   return 1;
> }
>
> and it reports
>
> t.c: In function ‘foo’:
> t.c:3:7: error: ‘t1’ undeclared (first use in this function)
>    if (t1 != 2)
>        ^~
> t.c:3:7: note: each undeclared identifier is reported only once for
> each function it appears in
> t.c:9:10: error: invalid conversion in return statement
>    return t1;
>           ^~
> t.c:1:14: note: declared here
>  int __GIMPLE foo(int a)
>               ^~~
>
> and thus doesn't ICE.
>
> Maybe one of my patches in this area made yours redundant (it doesn't
> apply cleanly anymore as well).

I have rebased and updated the patch.


Thanks,
Prasad

>
> Thanks,
> Richard.
>
>> Thanks,
>> Prasad
>>
>>> Richard.
>>>
>>>>
>>>> Thanks,
>>>> Prasad

[-- Attachment #2: undecl_var.patch --]
[-- Type: application/octet-stream, Size: 2810 bytes --]

diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c
index e167e42..7aad636 100644
--- a/gcc/c/gimple-parser.c
+++ b/gcc/c/gimple-parser.c
@@ -526,7 +526,9 @@ c_parser_gimple_binary_expression (c_parser *parser)
   rhs = c_parser_gimple_postfix_expression (parser);
   if (c_parser_error (parser))
     return ret;
-  ret.value = build2_loc (ret_loc, code, ret_type, lhs.value, rhs.value);
+
+  if (lhs.value != error_mark_node && rhs.value != error_mark_node)
+    ret.value = build2_loc (ret_loc, code, ret_type, lhs.value, rhs.value);
   return ret;
 }
 
@@ -560,6 +562,8 @@ c_parser_gimple_unary_expression (c_parser *parser)
       {
 	c_parser_consume_token (parser);
 	op = c_parser_gimple_postfix_expression (parser);
+	if (op.value == error_mark_node)
+	  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);
@@ -663,7 +667,7 @@ c_parser_parse_ssa_name (c_parser *parser,
 	  id = get_identifier (var_name);
 	  tree parent = lookup_name (id);
 	  XDELETEVEC (var_name);
-	  if (! parent)
+	  if (! parent || parent == error_mark_node)
 	    {
 	      c_parser_error (parser, "base variable or SSA name not declared"); 
 	      return error_mark_node;
@@ -1259,6 +1263,8 @@ c_parser_gimple_if_stmt (c_parser *parser, gimple_seq *seq)
   location_t loc;
   c_parser_consume_token (parser);
   tree cond = c_parser_gimple_paren_condition (parser);
+  if (cond == error_mark_node)
+    return;
 
   if (c_parser_next_token_is_keyword (parser, RID_GOTO))
     {
@@ -1317,7 +1323,7 @@ c_parser_gimple_if_stmt (c_parser *parser, gimple_seq *seq)
 static void
 c_parser_gimple_switch_stmt (c_parser *parser, gimple_seq *seq)
 {
-  c_expr cond_expr;
+  tree cond = error_mark_node;
   tree case_label, label;
   auto_vec<tree> labels;
   tree default_label = NULL_TREE;
@@ -1326,10 +1332,15 @@ c_parser_gimple_switch_stmt (c_parser *parser, gimple_seq *seq)
 
   if (! c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
     return;
-  cond_expr = c_parser_gimple_postfix_expression (parser);
+
+  cond = c_parser_gimple_postfix_expression (parser).value;
+
   if (! c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
     return;
 
+  if (cond == error_mark_node)
+    return;
+
   if (! c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
     return;
 
@@ -1441,7 +1452,7 @@ c_parser_gimple_switch_stmt (c_parser *parser, gimple_seq *seq)
     }
   if (! c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>"))
     return;
-  gimple_seq_add_stmt (seq, gimple_build_switch (cond_expr.value,
+  gimple_seq_add_stmt (seq, gimple_build_switch (cond,
 						 default_label, labels));
   gimple_seq_add_seq (seq, switch_body);
   labels.release();

[-- Attachment #3: Changelog --]
[-- Type: application/octet-stream, Size: 649 bytes --]

diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 1ab194a..4e8fd92 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,11 @@
+2016-12-28  Prasad Ghangal  <prasad.ghangal@gmail.com>
+	* gimple-parser.c (c_parser_gimple_binary_expression): Check
+	lhs.value and rhs.value before calling build2loc.
+	(c_parser_gimple_unary_expression): Check if op value is valid.
+	(c_parser_parse_ssa_name): Check if parent is valid.
+	(c_parser_gimple_if_stmt): Return if cond is error_mark_node.
+	(c_parser_gimple_switch_stmt): Likewise.
+
 2017-02-07  Richard Biener  <rguenther@suse.de>
 
 	* gimple-parser.c (c_parser_gimple_expr_list): Simplify.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH][GIMPLEFE] Fix for ICE due to undeclared variable
  2017-02-09  6:00       ` Prasad Ghangal
@ 2017-02-10 12:46         ` Richard Biener
  0 siblings, 0 replies; 7+ messages in thread
From: Richard Biener @ 2017-02-10 12:46 UTC (permalink / raw)
  To: Prasad Ghangal; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 7793 bytes --]

On Thu, Feb 9, 2017 at 7:00 AM, Prasad Ghangal <prasad.ghangal@gmail.com> wrote:
> On 7 February 2017 at 13:40, Richard Biener <richard.guenther@gmail.com> wrote:
>> On Mon, Feb 6, 2017 at 7:00 AM, Prasad Ghangal <prasad.ghangal@gmail.com> wrote:
>>> On 4 January 2017 at 16:02, Richard Biener <richard.guenther@gmail.com> wrote:
>>>> On Wed, Dec 28, 2016 at 7:27 PM, Prasad Ghangal
>>>> <prasad.ghangal@gmail.com> wrote:
>>>>> Hi,
>>>>> The attached patch tries fix ICE due to undeclared variable(s) in the input.
>>>>> Successfully bootstrapped on x86_64-pc-linux-gnu, testing is in progress
>>>>
>>>> Ok.
>>>>
>>> Can you please commit the patch? I don't have access for that.
>>
>> Can you share a testcase that broke?  I tried
>>
>
> Consider following testcases:
>
> Case 1:
> int __GIMPLE foo()
> {
>   if (a != 2)
>     goto bb1;
>   else
>     goto bb2;
>
> bb1:
>   a_1 = 10;
>   return a_1;
>
> bb2:
>   return 1;
> }
>
> gives:
>
>  foo
> gcc/test.c: In function ‘foo’:
> gcc/test.c:3:7: error: ‘a’ undeclared (first use in this function)
>    if (a != 2)
>        ^
> gcc/test.c:3:7: note: each undeclared identifier is reported only once
> for each function it appears in
> gcc/test.c:9:3: internal compiler error: in make_ssa_name_fn, at
> tree-ssanames.c:268
>    a_1 = 10;
>    ^~~
> 0x1199aa0 make_ssa_name_fn(function*, tree_node*, gimple*, unsigned int)
>         ../../git_gcc/gcc/tree-ssanames.c:265
> 0x839e2c c_parser_parse_ssa_name
>         ../../git_gcc/gcc/c/gimple-parser.c:675
> 0x83a5e6 c_parser_gimple_postfix_expression
>         ../../git_gcc/gcc/c/gimple-parser.c:845
> 0x839ac5 c_parser_gimple_unary_expression
>         ../../git_gcc/gcc/c/gimple-parser.c:603
> 0x838544 c_parser_gimple_statement
>         ../../git_gcc/gcc/c/gimple-parser.c:271
> 0x83848e c_parser_gimple_compound_statement
>         ../../git_gcc/gcc/c/gimple-parser.c:226
> 0x837fd2 c_parser_parse_gimple_body(c_parser*)
>         ../../git_gcc/gcc/c/gimple-parser.c:92
> 0x7f7bb5 c_parser_declaration_or_fndef
>         ../../git_gcc/gcc/c/c-parser.c:2091
> 0x7f628a c_parser_external_declaration
>         ../../git_gcc/gcc/c/c-parser.c:1468
> 0x7f5dd3 c_parser_translation_unit
>         ../../git_gcc/gcc/c/c-parser.c:1348
> 0x82a3c4 c_parse_file()
>         ../../git_gcc/gcc/c/c-parser.c:18185
> 0x89c5d9 c_common_parse_file()
>         ../../git_gcc/gcc/c-family/c-opts.c:1107
> Please submit a full bug report,
> with preprocessed source if appropriate.
> Please include the complete backtrace with any bug report.
> See <http://gcc.gnu.org/bugs.html> for instructions.
>
>
>
> Case 2:
>
> int __GIMPLE ()
> main (int argc, char * * argv)
> {
>
>   bb_2:
>   switch (a) {default: L2; case 1: L0; case 2: L1; }
>
> L0:
>   a = 0;
>   goto bb_6;
>
> L1:
>   a = 3;
>   goto L2;
>
> L2:
>   return a;
>
> }
>
>  main
> gcc/test3.c: In function ‘main’:
> gcc/test3.c:6:11: error: ‘a’ undeclared (first use in this function)
>    switch (a) {default: L2; case 1: L0; case 2: L1; }
>            ^
> gcc/test3.c:6:11: note: each undeclared identifier is reported only
> once for each function it appears in
> gcc/test3.c:6:3: internal compiler error: in gimple_switch_set_index,
> at gimple.h:4513
>    switch (a) {default: L2; case 1: L0; case 2: L1; }
>    ^~~~~~
> 0xb31385 gimple_switch_set_index
>         ../../git_gcc/gcc/gimple.h:4513
> 0xb33b3f gimple_build_switch_nlabels(unsigned int, tree_node*, tree_node*)
>         ../../git_gcc/gcc/gimple.c:757
> 0xb33b90 gimple_build_switch(tree_node*, tree_node*, vec<tree_node*,
> va_heap, vl_ptr>)
>         ../../git_gcc/gcc/gimple.c:773
> 0x83bd94 c_parser_gimple_switch_stmt
>         ../../git_gcc/gcc/c/gimple-parser.c:1445
> 0x83832c c_parser_gimple_compound_statement
>         ../../git_gcc/gcc/c/gimple-parser.c:175
> 0x837fd2 c_parser_parse_gimple_body(c_parser*)
>         ../../git_gcc/gcc/c/gimple-parser.c:92
> 0x7f7bb5 c_parser_declaration_or_fndef
>         ../../git_gcc/gcc/c/c-parser.c:2091
> 0x7f628a c_parser_external_declaration
>         ../../git_gcc/gcc/c/c-parser.c:1468
> 0x7f5dd3 c_parser_translation_unit
>         ../../git_gcc/gcc/c/c-parser.c:1348
> 0x82a3c4 c_parse_file()
>         ../../git_gcc/gcc/c/c-parser.c:18185
> 0x89c5d9 c_common_parse_file()
>         ../../git_gcc/gcc/c-family/c-opts.c:1107
> Please submit a full bug report,
> with preprocessed source if appropriate.
> Please include the complete backtrace with any bug report.
> See <http://gcc.gnu.org/bugs.html> for instructions.
>
>
> Case 3:
>
> void __GIMPLE () foo (int a)
> {
> bb_2:
>   a = *b;
>
> bb_3:
>   return;
> }
>
>  foo
> gcc/test6.c: In function ‘foo’:
> gcc/test6.c:5:8: error: ‘b’ undeclared (first use in this function)
>    a = *b;
>         ^
> gcc/test6.c:5:8: note: each undeclared identifier is reported only
> once for each function it appears in
> gcc/test6.c:5:3: internal compiler error: tree check: expected class
> ‘type’, have ‘exceptional’ (error_mark) in build_int_cst, at
> tree.c:1297
>    a = *b;
>    ^
> 0x125cd92 tree_class_check_failed(tree_node const*, tree_code_class,
> char const*, int, char const*)
>         ../../git_gcc/gcc/tree.c:9866
> 0x77f8e3 tree_class_check(tree_node*, tree_code_class, char const*,
> int, char const*)
>         ../../git_gcc/gcc/tree.h:3183
> 0x123db1e build_int_cst(tree_node*, long)
>         ../../git_gcc/gcc/tree.c:1297
> 0x124b279 build_simple_mem_ref_loc(unsigned int, tree_node*)
>         ../../git_gcc/gcc/tree.c:4634
> 0x8396a8 c_parser_gimple_unary_expression
>         ../../git_gcc/gcc/c/gimple-parser.c:565
> 0x838c9a c_parser_gimple_statement
>         ../../git_gcc/gcc/c/gimple-parser.c:339
> 0x83848e c_parser_gimple_compound_statement
>         ../../git_gcc/gcc/c/gimple-parser.c:226
> 0x837fd2 c_parser_parse_gimple_body(c_parser*)
>         ../../git_gcc/gcc/c/gimple-parser.c:92
> 0x7f7bb5 c_parser_declaration_or_fndef
>         ../../git_gcc/gcc/c/c-parser.c:2091
> 0x7f628a c_parser_external_declaration
>         ../../git_gcc/gcc/c/c-parser.c:1468
> 0x7f5dd3 c_parser_translation_unit
>         ../../git_gcc/gcc/c/c-parser.c:1348
> 0x82a3c4 c_parse_file()
>         ../../git_gcc/gcc/c/c-parser.c:18185
> 0x89c5d9 c_common_parse_file()
>         ../../git_gcc/gcc/c-family/c-opts.c:1107
> Please submit a full bug report,
> with preprocessed source if appropriate.
> Please include the complete backtrace with any bug report.
> See <http://gcc.gnu.org/bugs.html> for instructions.
>
>
>> int __GIMPLE foo(int a)
>> {
>>   if (t1 != 2)
>>     goto bb1;
>>   else
>>     goto bb2;
>>
>> bb1:
>>   return t1;
>>
>> bb2:
>>   return 1;
>> }
>>
>> and it reports
>>
>> t.c: In function ‘foo’:
>> t.c:3:7: error: ‘t1’ undeclared (first use in this function)
>>    if (t1 != 2)
>>        ^~
>> t.c:3:7: note: each undeclared identifier is reported only once for
>> each function it appears in
>> t.c:9:10: error: invalid conversion in return statement
>>    return t1;
>>           ^~
>> t.c:1:14: note: declared here
>>  int __GIMPLE foo(int a)
>>               ^~~
>>
>> and thus doesn't ICE.
>>
>> Maybe one of my patches in this area made yours redundant (it doesn't
>> apply cleanly anymore as well).
>
> I have rebased and updated the patch.

Thanks.  I have turned those into testcases and applied the attached
slighly changed patch.

Bootstrapped / tested on x86_64-unknown-linux-gnu.

Richard.

>
> Thanks,
> Prasad
>
>>
>> Thanks,
>> Richard.
>>
>>> Thanks,
>>> Prasad
>>>
>>>> Richard.
>>>>
>>>>>
>>>>> Thanks,
>>>>> Prasad

[-- Attachment #2: gimplefe-error-recovery-1 --]
[-- Type: application/octet-stream, Size: 5385 bytes --]

2017-02-10  Prasad Ghangal  <prasad.ghangal@gmail.com>
	Richard Biener  <rguenther@suse.de>

	* gimple-parser.c (c_parser_gimple_binary_expression): Avoid
	building IL when arguments are error_mark_node.
	(c_parser_gimple_unary_expression): Likewise.
	(c_parser_gimple_if_stmt): Likewise.
	(c_parser_gimple_switch_stmt): Likewise.
	(c_parser_gimple_return_stmt): Likewise.
	(c_parser_parse_ssa_name): When name lookup fails do not build
	an SSA name.  Use undeclared rather than not declared in error
	reporting.

	* gcc.dg/gimplefe-error-1.c: New testcase.
	* gcc.dg/gimplefe-error-2.c: New testcase.
	* gcc.dg/gimplefe-error-3.c: New testcase.

Index: gcc/c/gimple-parser.c
===================================================================
--- gcc/c/gimple-parser.c	(revision 245323)
+++ gcc/c/gimple-parser.c	(working copy)
@@ -524,9 +524,8 @@ c_parser_gimple_binary_expression (c_par
   location_t ret_loc = c_parser_peek_token (parser)->location;
   c_parser_consume_token (parser);
   rhs = c_parser_gimple_postfix_expression (parser);
-  if (c_parser_error (parser))
-    return ret;
-  ret.value = build2_loc (ret_loc, code, ret_type, lhs.value, rhs.value);
+  if (lhs.value != error_mark_node && rhs.value != error_mark_node)
+    ret.value = build2_loc (ret_loc, code, ret_type, lhs.value, rhs.value);
   return ret;
 }
 
@@ -560,6 +559,8 @@ c_parser_gimple_unary_expression (c_pars
       {
 	c_parser_consume_token (parser);
 	op = c_parser_gimple_postfix_expression (parser);
+	if (op.value == error_mark_node)
+	  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);
@@ -643,7 +644,7 @@ c_parser_parse_ssa_name (c_parser *parse
 	{
 	  if (! type)
 	    {
-	      c_parser_error (parser, "SSA name not declared"); 
+	      c_parser_error (parser, "SSA name undeclared"); 
 	      return error_mark_node;
 	    }
 	  name = make_ssa_name_fn (cfun, type, NULL, version);
@@ -663,9 +664,9 @@ c_parser_parse_ssa_name (c_parser *parse
 	  id = get_identifier (var_name);
 	  tree parent = lookup_name (id);
 	  XDELETEVEC (var_name);
-	  if (! parent)
+	  if (! parent || parent == error_mark_node)
 	    {
-	      c_parser_error (parser, "base variable or SSA name not declared"); 
+	      c_parser_error (parser, "base variable or SSA name undeclared"); 
 	      return error_mark_node;
 	    }
 	  if (VECTOR_TYPE_P (TREE_TYPE (parent))
@@ -1300,8 +1301,9 @@ c_parser_gimple_if_stmt (c_parser *parse
       return;
     }
 
-  gimple_seq_add_stmt (seq, gimple_build_cond_from_tree (cond, t_label,
-							 f_label));
+  if (cond != error_mark_node)
+    gimple_seq_add_stmt (seq, gimple_build_cond_from_tree (cond, t_label,
+							   f_label));
 }
 
 /* Parse gimple switch-statement.
@@ -1441,10 +1443,13 @@ c_parser_gimple_switch_stmt (c_parser *p
     }
   if (! c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>"))
     return;
-  gimple_seq_add_stmt (seq, gimple_build_switch (cond_expr.value,
-						 default_label, labels));
-  gimple_seq_add_seq (seq, switch_body);
-  labels.release();
+
+  if (cond_expr.value != error_mark_node)
+    {
+      gimple_seq_add_stmt (seq, gimple_build_switch (cond_expr.value,
+						     default_label, labels));
+      gimple_seq_add_seq (seq, switch_body);
+    }
 }
 
 /* Parse gimple return statement.  */
@@ -1465,9 +1470,12 @@ c_parser_gimple_return_stmt (c_parser *p
     {
       location_t xloc = c_parser_peek_token (parser)->location;
       c_expr expr = c_parser_gimple_unary_expression (parser);
-      c_finish_gimple_return (xloc, expr.value);
-      ret = gimple_build_return (expr.value);
-      gimple_seq_add_stmt (seq, ret);
+      if (expr.value != error_mark_node)
+	{
+	  c_finish_gimple_return (xloc, expr.value);
+	  ret = gimple_build_return (expr.value);
+	  gimple_seq_add_stmt (seq, ret);
+	}
     }
 }
 
Index: gcc/testsuite/gcc.dg/gimplefe-error-1.c
===================================================================
--- gcc/testsuite/gcc.dg/gimplefe-error-1.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/gimplefe-error-1.c	(working copy)
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-fgimple" } */
+
+void __GIMPLE () foo (int a)
+{
+bb_2:
+  a = *b; /* { dg-error "undeclared" } */
+
+bb_3:
+  return;
+}
Index: gcc/testsuite/gcc.dg/gimplefe-error-2.c
===================================================================
--- gcc/testsuite/gcc.dg/gimplefe-error-2.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/gimplefe-error-2.c	(working copy)
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-fgimple" } */
+
+int __GIMPLE ()
+main (int argc, char * * argv)
+{
+
+bb_2:
+  switch (a) {default: L2; case 1: L0; case 2: L1; } /* { dg-error "undeclared" } */
+
+L0:
+  a = 0;
+  goto bb_6;
+
+L1:
+  a = 3;
+  goto L2;
+
+L2:
+  return a;
+}
Index: gcc/testsuite/gcc.dg/gimplefe-error-3.c
===================================================================
--- gcc/testsuite/gcc.dg/gimplefe-error-3.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/gimplefe-error-3.c	(working copy)
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-fgimple" } */
+
+int __GIMPLE foo()
+{
+  if (a != 2) /* { dg-error "undeclared" } */
+    goto bb1;
+  else
+    goto bb2;
+
+bb1:
+  a_1 = 10; /* { dg-error "undeclared" } */
+  return a_1;
+
+bb2:
+  return 1;
+}

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-02-10 12:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-28 18:39 [PATCH][GIMPLEFE] Fix for ICE due to undeclared variable Prasad Ghangal
2016-12-28 19:16 ` Prasad Ghangal
2017-01-04 10:32 ` Richard Biener
2017-02-06  6:00   ` Prasad Ghangal
2017-02-07  8:10     ` Richard Biener
2017-02-09  6:00       ` Prasad Ghangal
2017-02-10 12:46         ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).