Bug 94705 - [8/9 Regression] internal compiler error: tree check: expected class ‘type’, have ‘exceptional’ (error_mark) in diag_attr_exclusions, at attribs.c:396 since r8-5161
Summary: [8/9 Regression] internal compiler error: tree check: expected class ‘type’, ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 10.0
: P4 normal
Target Milestone: 8.5
Assignee: Jakub Jelinek
URL:
Keywords: error-recovery, ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2020-04-22 07:06 UTC by John X
Modified: 2020-09-17 17:35 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-04-22 00:00:00


Attachments
gcc10-pr94705.patch (664 bytes, patch)
2020-04-22 08:21 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description John X 2020-04-22 07:06:26 UTC
$ gcc-10 --version
gcc (GCC) 10.0.1 20200419 (experimental)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

--------------------------------------------------------------------------------

$ cat test.c 
void sub_0 (void * arg_0){}

int sub_1 ( unsigned arg_0 ) { 
	if ( sub_0 ( sub_2 ) ) 
	{ 
		; 
	} 

	void __attribute__ ( ( noinline ) ) sub_2 ( int arg_0 );
}

--------------------------------------------------------------------------------

$ gcc-10 test.c 
test.c: In function ‘sub_1’:
test.c:4:15: error: ‘sub_2’ undeclared (first use in this function); did you mean ‘sub_1’?
    4 |  if ( sub_0 ( sub_2 ) )
      |               ^~~~~
      |               sub_1
test.c:4:15: note: each undeclared identifier is reported only once for each function it appears in
test.c:9:2: internal compiler error: tree check: expected class ‘type’, have ‘exceptional’ (error_mark) in diag_attr_exclusions, at attribs.c:396
    9 |  void __attribute__ ( ( noinline ) ) sub_2 ( int arg_0 );
      |  ^~~~
0x731f2f tree_class_check_failed(tree_node const*, tree_code_class, char const*, int, char const*)
	../../gcc-10-20200419/gcc/tree.c:9777
0x5eaf44 tree_class_check(tree_node*, tree_code_class, char const*, int, char const*)
	../../gcc-10-20200419/gcc/tree.h:3410
0x5eaf44 diag_attr_exclusions
	../../gcc-10-20200419/gcc/attribs.c:396
0x7d4fda diag_attr_exclusions
	../../gcc-10-20200419/gcc/attribs.c:379
0x7d6fb5 decl_attributes(tree_node**, tree_node*, int, tree_node*)
	../../gcc-10-20200419/gcc/attribs.c:694
0x7f2554 start_decl(c_declarator*, c_declspecs*, bool, tree_node*)
	../../gcc-10-20200419/gcc/c/c-decl.c:5117
0x84cdd5 c_parser_declaration_or_fndef
	../../gcc-10-20200419/gcc/c/c-parser.c:2271
0x8302bf c_parser_compound_statement_nostart
	../../gcc-10-20200419/gcc/c/c-parser.c:5718
0x84c8c4 c_parser_compound_statement
	../../gcc-10-20200419/gcc/c/c-parser.c:5617
0x84e381 c_parser_declaration_or_fndef
	../../gcc-10-20200419/gcc/c/c-parser.c:2505
0x8566e3 c_parser_external_declaration
	../../gcc-10-20200419/gcc/c/c-parser.c:1745
0x8571e1 c_parser_translation_unit
	../../gcc-10-20200419/gcc/c/c-parser.c:1618
0x8571e1 c_parse_file()
	../../gcc-10-20200419/gcc/c/c-parser.c:21745
0x8ae2cb c_common_parse_file()
	../../gcc-10-20200419/gcc/c-family/c-opts.c:1190
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

--------------------------------------------------------------------------------

$ gcc-9 --version
gcc (GCC) 9.2.1 20191102
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

--------------------------------------------------------------------------------

$ gcc-9 test.c 
test.c: In function ‘sub_1’:
test.c:4:15: error: ‘sub_2’ undeclared (first use in this function); did you mean ‘sub_1’?
    4 |  if ( sub_0 ( sub_2 ) )
      |               ^~~~~
      |               sub_1
test.c:4:15: note: each undeclared identifier is reported only once for each function it appears in
test.c:9: confused by earlier errors, bailing out
Comment 1 Jakub Jelinek 2020-04-22 07:27:07 UTC
Started with r8-5161-g5d9ae53d70c72991e26648d915e7fb8e00b8e811
Comment 2 Jakub Jelinek 2020-04-22 07:30:07 UTC
Slightly reduced:
void foo ();

int
bar (void)
{
  foo (baz);
  void __attribute__ ((noinline)) baz (void);
}
Comment 3 Jakub Jelinek 2020-04-22 08:21:20 UTC
Created attachment 48334 [details]
gcc10-pr94705.patch

Untested fix.
Comment 4 CVS Commits 2020-04-23 07:55:14 UTC
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:e2a71816b4949225498bec37e947293aa7f5841b

commit r10-7906-ge2a71816b4949225498bec37e947293aa7f5841b
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Apr 23 09:54:14 2020 +0200

    attribs: Don't diagnose attribute exclusions during error recovery [PR94705]
    
    On the following testcase GCC ICEs, because last_decl is error_mark_node,
    and diag_attr_exclusions assumes that if it is not NULL, it must be a decl.
    
    The following patch just doesn't diagnose attribute exclusions if the
    other decl is erroneous (and thus we've already reported errors for it).
    
    2020-04-23  Jakub Jelinek  <jakub@redhat.com>
    
            PR c/94705
            * attribs.c (decl_attribute): Don't diagnose attribute exclusions
            if last_decl is error_mark_node or has such a TREE_TYPE.
    
            * gcc.dg/pr94705.c: New test.
Comment 5 Jakub Jelinek 2020-04-23 08:13:18 UTC
Fixed for 10.1+ for now.
Comment 6 CVS Commits 2020-09-16 19:20:48 UTC
The releases/gcc-9 branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:934ede34973909eb15b678f88395d83be01433e7

commit r9-8883-g934ede34973909eb15b678f88395d83be01433e7
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Apr 23 09:54:14 2020 +0200

    attribs: Don't diagnose attribute exclusions during error recovery [PR94705]
    
    On the following testcase GCC ICEs, because last_decl is error_mark_node,
    and diag_attr_exclusions assumes that if it is not NULL, it must be a decl.
    
    The following patch just doesn't diagnose attribute exclusions if the
    other decl is erroneous (and thus we've already reported errors for it).
    
    2020-04-23  Jakub Jelinek  <jakub@redhat.com>
    
            PR c/94705
            * attribs.c (decl_attribute): Don't diagnose attribute exclusions
            if last_decl is error_mark_node or has such a TREE_TYPE.
    
            * gcc.dg/pr94705.c: New test.
    
    (cherry picked from commit e2a71816b4949225498bec37e947293aa7f5841b)
Comment 7 Jakub Jelinek 2020-09-17 17:35:31 UTC
Fixed for 8.5 in r8-10490-g1dd77eeccc2941323607e88a6fe37625a2dc6698 and by the above commit for 9.4+ too.