Bug 102434

Summary: [11/12 Regression] ICE in output_constructor_regular_field, at varasm.c:5514 since r11-4547-g6fb7e3c29188ab7c
Product: gcc Reporter: G. Steinmetz <gscfq>
Component: c++Assignee: Marek Polacek <mpolacek>
Status: RESOLVED FIXED    
Severity: normal CC: marxin, mpolacek, webrown.cpp
Priority: P2 Keywords: ice-on-invalid-code
Version: 12.0   
Target Milestone: 11.3   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2021-09-21 00:00:00

Description G. Steinmetz 2021-09-21 19:21:29 UTC
Started between 20201018 and 20201108 :
(derived from initlist-deduce3.C)


$ cat z1.cc
using size_t = decltype(sizeof 0);
namespace std {
  template<typename T> union initializer_list {
    const T *ptr;
    size_t n;
  };
}
template<typename T>
void Task() {}
auto b = { &Task<int> };


$ g++-12-20210919 -c z1.cc
z1.cc:10:24: internal compiler error: in output_constructor_regular_field, at varasm.c:5514
   10 | auto b = { &Task<int> };
      |                        ^
0x1025b84 output_constructor_regular_field
        ../../gcc/varasm.c:5514
0x1025b84 output_constructor
        ../../gcc/varasm.c:5826
0x1025ecf output_constant
        ../../gcc/varasm.c:5172
0x1025ecf assemble_variable_contents
        ../../gcc/varasm.c:2235
0x102dcad assemble_variable(tree_node*, int, int, int)
        ../../gcc/varasm.c:2414
0x102ffaa varpool_node::assemble_decl()
        ../../gcc/varpool.c:595
0x96ac1f output_in_order
        ../../gcc/cgraphunit.c:2135
0x96ac1f symbol_table::compile()
        ../../gcc/cgraphunit.c:2353
0x96d54f symbol_table::compile()
        ../../gcc/cgraphunit.c:2540
0x96d54f symbol_table::finalize_compilation_unit()
        ../../gcc/cgraphunit.c:2537
Comment 1 Andrew Pinski 2021-09-21 23:49:45 UTC
Confirmed.
Note clang also ICEs :).
Comment 2 Martin Liška 2021-09-27 13:24:44 UTC
Started with r11-4547-g6fb7e3c29188ab7c.
Comment 3 GCC Commits 2022-01-31 20:35:48 UTC
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

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

commit r12-6951-gb1a8b92f8f78536a00012e2e53a0d12ddbe6836d
Author: Marek Polacek <polacek@redhat.com>
Date:   Fri Jan 28 20:01:06 2022 -0500

    c++: Reject union std::initializer_list [PR102434]
    
    Weird things are going to happen if you define your std::initializer_list
    as a union.  In this case, we crash in output_constructor_regular_field.
    
    Let's not allow such a definition in the first place.
    
            PR c++/102434
    
    gcc/cp/ChangeLog:
    
            * class.cc (finish_struct): Don't allow union initializer_list.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp0x/initlist128.C: New test.
Comment 4 Marek Polacek 2022-01-31 20:38:24 UTC
Fixed.