Bug 98198 - [11/12 Regression] internal compiler error: tree check: expected class ‘type’, have ‘exceptional’ (error_mark) in decl_or_type_attrs
Summary: [11/12 Regression] internal compiler error: tree check: expected class ‘type’...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 11.0
: P4 normal
Target Milestone: 12.0
Assignee: Not yet assigned to anyone
URL:
Keywords: error-recovery, ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2020-12-08 12:28 UTC by John X
Modified: 2022-03-17 15:15 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-12-08 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John X 2020-12-08 12:28:01 UTC
$ cat test-6951.c 

static inline void sub_1 ( ) { 
	struct struct_1 var_9 , var_10
}

static int var_9[1] __attribute__ ( ( section ( ".data" ) ) ) ; 

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

$ gcc-11 --version
gcc (GCC) 11.0.0 20201129 (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.

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

$ gcc-11 test-6951.c 
test-6951.c: In function ‘sub_1’:
test-6951.c:3:25: error: storage size of ‘var_9’ isn’t known
    3 |         struct struct_1 var_9 , var_10
      |                         ^~~~~
test-6951.c:4:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘}’ token
    4 | }
      | ^
test-6951.c:6:1: internal compiler error: tree check: expected class ‘type’, have ‘exceptional’ (error_mark) in decl_or_type_attrs, at c-family/c-attribs.c:775
    6 | static int var_9[1] __attribute__ ( ( section ( ".data" ) ) ) ;
      | ^~~~~~
0x753c11 tree_class_check_failed(tree_node const*, tree_code_class, char const*, int, char const*)
	../../gcc-11-20201129/gcc/tree.c:9860
0x642f30 tree_class_check(tree_node*, tree_code_class, char const*, int, char const*)
	../../gcc-11-20201129/gcc/tree.h:3454
0x642f30 decl_or_type_attrs
	../../gcc-11-20201129/gcc/c-family/c-attribs.c:775
0x642f30 validate_attr_args
	../../gcc-11-20201129/gcc/c-family/c-attribs.c:803
0x90691d validate_attr_arg
	../../gcc-11-20201129/gcc/c-family/c-attribs.c:889
0x90691d handle_section_attribute
	../../gcc-11-20201129/gcc/c-family/c-attribs.c:2132
0x80d0dc decl_attributes(tree_node**, tree_node*, int, tree_node*)
	../../gcc-11-20201129/gcc/attribs.c:723
0x8295f2 start_decl(c_declarator*, c_declspecs*, bool, tree_node*, unsigned int*)
	../../gcc-11-20201129/gcc/c/c-decl.c:5188
0x884e32 c_parser_declaration_or_fndef
	../../gcc-11-20201129/gcc/c/c-parser.c:2302
0x867ef0 c_parser_compound_statement_nostart
	../../gcc-11-20201129/gcc/c/c-parser.c:5700
0x8848f5 c_parser_compound_statement
	../../gcc-11-20201129/gcc/c/c-parser.c:5597
0x886378 c_parser_declaration_or_fndef
	../../gcc-11-20201129/gcc/c/c-parser.c:2539
0x88dbe3 c_parser_external_declaration
	../../gcc-11-20201129/gcc/c/c-parser.c:1777
0x88e629 c_parser_translation_unit
	../../gcc-11-20201129/gcc/c/c-parser.c:1650
0x88e629 c_parse_file()
	../../gcc-11-20201129/gcc/c/c-parser.c:21877
0x8ebdfd c_common_parse_file()
	../../gcc-11-20201129/gcc/c-family/c-opts.c:1198
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-10 --version
gcc (GCC) 10.2.1 20201128
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.

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

$ gcc-10 test-6951.c 
test-6951.c: In function ‘sub_1’:
test-6951.c:3:18: error: storage size of ‘var_9’ isn’t known
    3 |  struct struct_1 var_9 , var_10
      |                  ^~~~~
test-6951.c:4:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘}’ token
    4 | }
      | ^
test-6951.c:6:1: error: expected declaration or statement at end of input
    6 | static int var_9[1] __attribute__ ( ( section ( ".data" ) ) ) ;
      | ^~~~~~
Comment 1 Martin Liška 2020-12-08 19:57:47 UTC
Started with r10-2526-gf0033821c1c9ba38.
Comment 2 Christophe Lyon 2020-12-08 20:28:27 UTC
Can you check with gcc trunk?
There were recent fixes in the handling of noinit/persistent attribute:
g:762ca20364a590be2cb9c79c0101ccbff74b5de1
Comment 3 Martin Liška 2020-12-08 20:31:35 UTC
The current master is still affected.
Comment 4 Christophe Lyon 2020-12-08 23:13:49 UTC
This simple patch avoids the ICE:

diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index 1d2ab7c..8847932 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -767,6 +767,10 @@ decl_or_type_attrs (tree node)
        return attrs;
 
       tree type = TREE_TYPE (node);
+
+      if (type == error_mark_node)
+       return NULL_TREE;
+
       return TYPE_ATTRIBUTES (type);
     }
Comment 5 Jakub Jelinek 2021-04-27 11:39:46 UTC
GCC 11.1 has been released, retargeting bugs to GCC 11.2.
Comment 6 Richard Biener 2021-07-28 07:05:27 UTC
GCC 11.2 is being released, retargeting bugs to GCC 11.3
Comment 7 GCC Commits 2022-03-16 23:21:36 UTC
The master branch has been updated by Roger Sayle <sayle@gcc.gnu.org>:

https://gcc.gnu.org/g:4565a07a646949e6ce30a08c60484afe1fed0ac1

commit r12-7681-g4565a07a646949e6ce30a08c60484afe1fed0ac1
Author: Roger Sayle <roger@nextmovesoftware.com>
Date:   Wed Mar 16 23:20:34 2022 +0000

    PR c/98198: ICE-on-invalid-code error recovery.
    
    This is Christophe Lyon's fix to PR c/98198, an ICE-on-invalid-code
    regression affecting mainline, and a suitable testcase.
    Tested on x86_64-pc-linux-gnu with make bootstrap and make -k check
    with no new failures.  Ok for mainline?
    
    2022-03-16  Christophe Lyon  <christophe.lyon@arm.com>
                Roger Sayle  <roger@nextmovesoftware.com>
    
    gcc/c-family/ChangeLog
            PR c/98198
            * c-attribs.cc (decl_or_type_attrs): Add error_mark_node check.
    
    gcc/testsuite/ChangeLog
            PR c/98198
            * gcc.dg/pr98198.c: New test case.
Comment 8 Roger Sayle 2022-03-17 15:15:48 UTC
This has now been fixed on mainline.