Bug 84665 - [7/8 Regression] internal compiler error: in build_value_init, at cp/init.c:343
Summary: [7/8 Regression] internal compiler error: in build_value_init, at cp/init.c:343
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.0.1
: P2 normal
Target Milestone: 7.4
Assignee: Jason Merrill
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2018-03-02 09:46 UTC by Vegard Nossum
Modified: 2018-04-05 18:28 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-03-02 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vegard Nossum 2018-03-02 09:46:18 UTC
Input:

struct {
} a[1];

template<int &&>
void b() {
        __attribute__((noinline(a[0]))) int c = 0;
}

Output:

$ xgcc -x c++ -S -
<stdin>: In function 'void b()':
<stdin>:6:38: internal compiler error: in build_value_init, at cp/init.c:343
0xcfbe2b build_value_init(tree_node*, int)
        /home/vegard/git/gcc/gcc/cp/init.c:342
0xa47056 cxx_eval_array_reference
        /home/vegard/git/gcc/gcc/cp/constexpr.c:2458
0xa339b0 cxx_eval_constant_expression
        /home/vegard/git/gcc/gcc/cp/constexpr.c:4470
0xa4e0da cxx_eval_outermost_constant_expr
        /home/vegard/git/gcc/gcc/cp/constexpr.c:4827
0xa5b966 maybe_constant_value(tree_node*, tree_node*)
        /home/vegard/git/gcc/gcc/cp/constexpr.c:5044
0xc43ac2 cp_check_const_attributes
        /home/vegard/git/gcc/gcc/cp/decl2.c:1415
0xc43ac2 cplus_decl_attributes(tree_node**, tree_node*, int)
        /home/vegard/git/gcc/gcc/cp/decl2.c:1531
0xc1974a start_decl(cp_declarator const*, cp_decl_specifier_seq*, int, tree_node*, tree_node*, tree_node**)
        /home/vegard/git/gcc/gcc/cp/decl.c:5050
0xfa391c cp_parser_init_declarator
        /home/vegard/git/gcc/gcc/cp/parser.c:19591
0xfa9757 cp_parser_simple_declaration
        /home/vegard/git/gcc/gcc/cp/parser.c:13063
0xfaf948 cp_parser_block_declaration
        /home/vegard/git/gcc/gcc/cp/parser.c:12881
0xfb1e14 cp_parser_declaration_statement
        /home/vegard/git/gcc/gcc/cp/parser.c:12474
0xefdd8b cp_parser_statement
        /home/vegard/git/gcc/gcc/cp/parser.c:10923
0xf0184b cp_parser_statement_seq_opt
        /home/vegard/git/gcc/gcc/cp/parser.c:11272
0xf022ea cp_parser_compound_statement
        /home/vegard/git/gcc/gcc/cp/parser.c:11226
0xf967eb cp_parser_function_body
        /home/vegard/git/gcc/gcc/cp/parser.c:21769
0xf967eb cp_parser_ctor_initializer_opt_and_function_body
        /home/vegard/git/gcc/gcc/cp/parser.c:21804
0xf9f9f5 cp_parser_function_definition_after_declarator
        /home/vegard/git/gcc/gcc/cp/parser.c:26809
0xfa604d cp_parser_function_definition_from_specifiers_and_declarator
        /home/vegard/git/gcc/gcc/cp/parser.c:26726
0xfa604d cp_parser_init_declarator
        /home/vegard/git/gcc/gcc/cp/parser.c:19493

$ xgcc --version
xgcc (GCC) 8.0.1 20180301 (experimental)

Built from git c435a9e730c6e8f10da09d58b4fc9aaeb401b0d5 (r258097).

Seems to have appeared between 6.3.0 and 7.1.0.

Test case was minimised by C-Reduce.
Comment 1 Jakub Jelinek 2018-03-02 10:36:13 UTC
struct S {} a[1];

template <int N>
void
foo ()
{
  __attribute__ ((noinline (a[0]))) int c = 0;
}

Started with r239267, before it has been rejected:

pr84665.C: In function ‘void foo()’:
pr84665.C:7:41: error: wrong number of arguments specified for ‘noinline’ attribute
   __attribute__ ((noinline (a[0]))) int c = 0;
                                         ^
Comment 2 Jakub Jelinek 2018-03-02 11:46:12 UTC
We don't ICE with
struct S { int s; } a[1];
but do ICE with e.g.
struct S { constexpr S () {} } a[1];

build_value_init has:
341	  /* The AGGR_INIT_EXPR tweaking below breaks in templates.  */
342	  gcc_assert (!processing_template_decl
343		      || (SCALAR_TYPE_P (type) || TREE_CODE (type) == ARRAY_TYPE));
early, and type in this case is RECORD_TYPE S.
Called from:
2456	  /* If it's within the array bounds but doesn't have an explicit
2457	     initializer, it's value-initialized.  */
2458	  tree val = build_value_init (elem_type, tf_warning_or_error);
2459	  return cxx_eval_constant_expression (ctx, val, lval, non_constant_p,
2460					       overflow_p);
because a doesn't have explicit initializer.
No idea what to do here...
Comment 3 Jakub Jelinek 2018-03-19 11:52:58 UTC
Related to PR84940.
Comment 4 Jason Merrill 2018-04-05 16:04:39 UTC
Author: jason
Date: Thu Apr  5 16:04:08 2018
New Revision: 259132

URL: https://gcc.gnu.org/viewcvs?rev=259132&root=gcc&view=rev
Log:
	PR c++/84665 - ICE with array of empty class.

	* decl2.c (cp_check_const_attributes): Use fold_non_dependent_expr.

Added:
    trunk/gcc/testsuite/g++.dg/ext/attr-noinline-4.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl2.c
Comment 5 Jason Merrill 2018-04-05 18:28:17 UTC
Author: jason
Date: Thu Apr  5 18:27:43 2018
New Revision: 259146

URL: https://gcc.gnu.org/viewcvs?rev=259146&root=gcc&view=rev
Log:
	PR c++/84665 - ICE with array of empty class.

	* decl2.c (cp_check_const_attributes): Use fold_non_dependent_expr.

Added:
    branches/gcc-7-branch/gcc/testsuite/g++.dg/ext/attr-noinline-4.C
Modified:
    branches/gcc-7-branch/gcc/cp/ChangeLog
    branches/gcc-7-branch/gcc/cp/decl2.c
Comment 6 Jason Merrill 2018-04-05 18:28:55 UTC
Fixed.