The following related 4 code snippets trigger ICEs on trunk in different parts of the compiler: The first one crashes without any compiler options: ========================= void foo(int n) { int a[2][n] = {}; } ========================= bug.cc: In function 'void foo(int)': bug.cc:3:18: internal compiler error: in make_decl_rtl, at varasm.c:1214 int a[2][n] = {}; ^ 0xd24d63 make_decl_rtl(tree_node*) ../../gcc/gcc/varasm.c:1210 0x8a9409 expand_expr_real_1(tree_node*, rtx_def*, machine_mode, expand_modifier, rtx_def**) ../../gcc/gcc/expr.c:9320 0x8be7e7 expand_constructor ../../gcc/gcc/expr.c:7713 0x8a9244 expand_expr_real_1(tree_node*, rtx_def*, machine_mode, expand_modifier, rtx_def**) ../../gcc/gcc/expr.c:9557 0x8b3158 store_expr(tree_node*, rtx_def*, int, bool) ../../gcc/gcc/expr.c:5207 0x8b5569 expand_assignment(tree_node*, tree_node*, bool) ../../gcc/gcc/expr.c:4853 0x7df05d expand_gimple_stmt_1 ../../gcc/gcc/cfgexpand.c:2274 0x7df05d expand_gimple_stmt ../../gcc/gcc/cfgexpand.c:2370 0x7e0ab3 expand_gimple_basic_block ../../gcc/gcc/cfgexpand.c:4209 0x7e23dc gimple_expand_cfg ../../gcc/gcc/cfgexpand.c:4728 0x7e23dc execute ../../gcc/gcc/cfgexpand.c:4942 Please submit a full bug report, [etc.] The second one crashes if compiled with "-std=c++11": ========================= void foo(int n) { int a[n][2] = {}; } ========================= bug.cc: In function 'void foo(int)': bug.cc:3:18: internal compiler error: in gimplify_init_constructor, at gimplify.c:4236 int a[n][2] = {}; ^ 0x96f293 gimplify_init_constructor ../../gcc/gcc/gimplify.c:4236 0x970a7e gimplify_modify_expr_rhs ../../gcc/gcc/gimplify.c:4518 0x970de4 gimplify_modify_expr ../../gcc/gcc/gimplify.c:4834 0x9661d5 gimplify_expr(tree_node**, gimple_statement_d**, gimple_statement_d**, bool (*)(tree_node*), int) ../../gcc/gcc/gimplify.c:7332 0x9691a6 gimplify_stmt(tree_node**, gimple_statement_d**) ../../gcc/gcc/gimplify.c:5709 0x9656fe gimplify_cleanup_point_expr ../../gcc/gcc/gimplify.c:5485 0x9656fe gimplify_expr(tree_node**, gimple_statement_d**, gimple_statement_d**, bool (*)(tree_node*), int) ../../gcc/gcc/gimplify.c:7669 0x9691a6 gimplify_stmt(tree_node**, gimple_statement_d**) ../../gcc/gcc/gimplify.c:5709 0x964f9b gimplify_statement_list ../../gcc/gcc/gimplify.c:1525 0x964f9b gimplify_expr(tree_node**, gimple_statement_d**, gimple_statement_d**, bool (*)(tree_node*), int) ../../gcc/gcc/gimplify.c:7721 0x9691a6 gimplify_stmt(tree_node**, gimple_statement_d**) ../../gcc/gcc/gimplify.c:5709 0x964f9b gimplify_statement_list ../../gcc/gcc/gimplify.c:1525 0x964f9b gimplify_expr(tree_node**, gimple_statement_d**, gimple_statement_d**, bool (*)(tree_node*), int) ../../gcc/gcc/gimplify.c:7721 0x9691a6 gimplify_stmt(tree_node**, gimple_statement_d**) ../../gcc/gcc/gimplify.c:5709 0x9656fe gimplify_cleanup_point_expr ../../gcc/gcc/gimplify.c:5485 0x9656fe gimplify_expr(tree_node**, gimple_statement_d**, gimple_statement_d**, bool (*)(tree_node*), int) ../../gcc/gcc/gimplify.c:7669 0x9691a6 gimplify_stmt(tree_node**, gimple_statement_d**) ../../gcc/gcc/gimplify.c:5709 0x964f9b gimplify_statement_list ../../gcc/gcc/gimplify.c:1525 0x964f9b gimplify_expr(tree_node**, gimple_statement_d**, gimple_statement_d**, bool (*)(tree_node*), int) ../../gcc/gcc/gimplify.c:7721 0x9691a6 gimplify_stmt(tree_node**, gimple_statement_d**) ../../gcc/gcc/gimplify.c:5709 Please submit a full bug report, [etc.] The third one also crashes if compiled with "-std=c++11": ========================= void foo(int n) { int a[n][2][n] = {}; } ========================= bug.cc: In function 'void foo(int)': bug.cc:3:21: internal compiler error: in create_tmp_var, at gimplify.c:438 int a[n][2][n] = {}; ^ 0x962923 create_tmp_var(tree_node*, char const*) ../../gcc/gcc/gimplify.c:438 0x9641fc create_tmp_from_val ../../gcc/gcc/gimplify.c:521 0x9641fc lookup_tmp_var ../../gcc/gcc/gimplify.c:543 0x9641fc internal_get_tmp_var ../../gcc/gcc/gimplify.c:587 0x964bae gimplify_expr(tree_node**, gimple_statement_d**, gimple_statement_d**, bool (*)(tree_node*), int) ../../gcc/gcc/gimplify.c:8163 0x96bb54 gimplify_compound_lval ../../gcc/gcc/gimplify.c:2257 0x965fa4 gimplify_expr(tree_node**, gimple_statement_d**, gimple_statement_d**, bool (*)(tree_node*), int) ../../gcc/gcc/gimplify.c:7284 0x965010 gimplify_expr(tree_node**, gimple_statement_d**, gimple_statement_d**, bool (*)(tree_node*), int) ../../gcc/gcc/gimplify.c:7728 0x970f58 gimplify_modify_expr ../../gcc/gcc/gimplify.c:4875 0x9661d5 gimplify_expr(tree_node**, gimple_statement_d**, gimple_statement_d**, bool (*)(tree_node*), int) ../../gcc/gcc/gimplify.c:7332 0x9691a6 gimplify_stmt(tree_node**, gimple_statement_d**) ../../gcc/gcc/gimplify.c:5709 0x9656fe gimplify_cleanup_point_expr ../../gcc/gcc/gimplify.c:5485 0x9656fe gimplify_expr(tree_node**, gimple_statement_d**, gimple_statement_d**, bool (*)(tree_node*), int) ../../gcc/gcc/gimplify.c:7669 0x9691a6 gimplify_stmt(tree_node**, gimple_statement_d**) ../../gcc/gcc/gimplify.c:5709 0x964f9b gimplify_statement_list ../../gcc/gcc/gimplify.c:1525 0x964f9b gimplify_expr(tree_node**, gimple_statement_d**, gimple_statement_d**, bool (*)(tree_node*), int) ../../gcc/gcc/gimplify.c:7721 0x9691a6 gimplify_stmt(tree_node**, gimple_statement_d**) ../../gcc/gcc/gimplify.c:5709 0x964f9b gimplify_statement_list ../../gcc/gcc/gimplify.c:1525 0x964f9b gimplify_expr(tree_node**, gimple_statement_d**, gimple_statement_d**, bool (*)(tree_node*), int) ../../gcc/gcc/gimplify.c:7721 0x9691a6 gimplify_stmt(tree_node**, gimple_statement_d**) ../../gcc/gcc/gimplify.c:5709 Please submit a full bug report, [etc.] The last one crashes if compiled with "-std=c++1y": ========================= void foo(int n) { int a[n][n] = {}; } ========================= bug.cc: In function 'void foo(int)': bug.cc:3:13: warning: array of array of runtime bound [-Wvla] int a[n][n] = {}; ^ bug.cc:3:18: internal compiler error: in build2_stat, at tree.c:4104 int a[n][n] = {}; ^ 0xce51e0 build2_stat(tree_code, tree_node*, tree_node*, tree_node*) ../../gcc/gcc/tree.c:4103 0x9026bf build2_stat_loc ../../gcc/gcc/tree.h:3391 0x9026bf fold_build2_stat_loc(unsigned int, tree_code, tree_node*, tree_node*, tree_node*) ../../gcc/gcc/fold-const.c:15053 0x96b573 gimplify_self_mod_expr(tree_node**, gimple_statement_d**, gimple_statement_d**, bool, tree_node*) ../../gcc/gcc/gimplify.c:2375 0x965d6d gimplify_expr(tree_node**, gimple_statement_d**, gimple_statement_d**, bool (*)(tree_node*), int) ../../gcc/gcc/gimplify.c:7274 0x9691a6 gimplify_stmt(tree_node**, gimple_statement_d**) ../../gcc/gcc/gimplify.c:5709 0x964f9b gimplify_statement_list ../../gcc/gcc/gimplify.c:1525 0x964f9b gimplify_expr(tree_node**, gimple_statement_d**, gimple_statement_d**, bool (*)(tree_node*), int) ../../gcc/gcc/gimplify.c:7721 0x9691a6 gimplify_stmt(tree_node**, gimple_statement_d**) ../../gcc/gcc/gimplify.c:5709 0x964f9b gimplify_statement_list ../../gcc/gcc/gimplify.c:1525 0x964f9b gimplify_expr(tree_node**, gimple_statement_d**, gimple_statement_d**, bool (*)(tree_node*), int) ../../gcc/gcc/gimplify.c:7721 0x9691a6 gimplify_stmt(tree_node**, gimple_statement_d**) ../../gcc/gcc/gimplify.c:5709 0x9656fe gimplify_cleanup_point_expr ../../gcc/gcc/gimplify.c:5485 0x9656fe gimplify_expr(tree_node**, gimple_statement_d**, gimple_statement_d**, bool (*)(tree_node*), int) ../../gcc/gcc/gimplify.c:7669 0x9691a6 gimplify_stmt(tree_node**, gimple_statement_d**) ../../gcc/gcc/gimplify.c:5709 0x964f9b gimplify_statement_list ../../gcc/gcc/gimplify.c:1525 0x964f9b gimplify_expr(tree_node**, gimple_statement_d**, gimple_statement_d**, bool (*)(tree_node*), int) ../../gcc/gcc/gimplify.c:7721 0x9691a6 gimplify_stmt(tree_node**, gimple_statement_d**) ../../gcc/gcc/gimplify.c:5709 0x969e7d gimplify_bind_expr ../../gcc/gcc/gimplify.c:1213 0x965f50 gimplify_expr(tree_node**, gimple_statement_d**, gimple_statement_d**, bool (*)(tree_node*), int) ../../gcc/gcc/gimplify.c:7503 Please submit a full bug report, [etc.]
Jason, you did some VLA related work for c++1y. Would you mind having a look? Thanks!
All of them are probably related to r198745 (N3639 C++1y VLA support).
Still crashes with the top of trunk (6.0) as well as 5.3. $ cat z.cpp && /build/gcc-trunk/gcc/xgcc -B /build/gcc-trunk/gcc -Wall -Wextra -Wpedantic z.cpp void bar (int n) { char a [2][n] = { }; } z.cpp: In function ‘void bar(int)’: z.cpp:3:15: warning: ISO C++ forbids variable length array ‘a’ [-Wvla] char a [2][n] = { }; ^ z.cpp:3:8: warning: unused variable ‘a’ [-Wunused-variable] char a [2][n] = { }; ^ z.cpp:3:21: internal compiler error: in make_decl_rtl, at varasm.c:1299 char a [2][n] = { }; ^ 0x1449b13 make_decl_rtl(tree_node*) /src/gcc/trunk/gcc/varasm.c:1295 0xcd7cb5 expand_expr_real_1(tree_node*, rtx_def*, machine_mode, expand_modifier, rtx_def**, bool) /src/gcc/trunk/gcc/expr.c:9612 0xcd0ead expand_expr_real(tree_node*, rtx_def*, machine_mode, expand_modifier, rtx_def**, bool) /src/gcc/trunk/gcc/expr.c:7962 0xcb8d57 expand_expr /src/gcc/trunk/gcc/expr.h:256 0xcdfdc2 expr_size(tree_node*) /src/gcc/trunk/gcc/expr.c:11633 0xcd0b99 expand_constructor /src/gcc/trunk/gcc/expr.c:7829 0xcd9123 expand_expr_real_1(tree_node*, rtx_def*, machine_mode, expand_modifier, rtx_def**, bool) /src/gcc/trunk/gcc/expr.c:9879 0xcd0ead expand_expr_real(tree_node*, rtx_def*, machine_mode, expand_modifier, rtx_def**, bool) /src/gcc/trunk/gcc/expr.c:7962 0xcc8175 store_expr_with_bounds(tree_node*, rtx_def*, int, bool, bool, tree_node*) /src/gcc/trunk/gcc/expr.c:5406 0xcc8d79 store_expr(tree_node*, rtx_def*, int, bool, bool) /src/gcc/trunk/gcc/expr.c:5596 0xccd436 store_field /src/gcc/trunk/gcc/expr.c:6808 0xcc6247 expand_assignment(tree_node*, tree_node*, bool) /src/gcc/trunk/gcc/expr.c:5021 0xb8120c expand_gimple_stmt_1 /src/gcc/trunk/gcc/cfgexpand.c:3618 0xb815fd expand_gimple_stmt /src/gcc/trunk/gcc/cfgexpand.c:3714 0xb8870e expand_gimple_basic_block /src/gcc/trunk/gcc/cfgexpand.c:5720 0xb8a1d7 execute /src/gcc/trunk/gcc/cfgexpand.c:6335 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.
Updating Summary to make it clear that the ICE depends on the VLA having multiple dimensions at least one of which being a constant expression, and the initializer list being empty.
Actually, the ICE can be triggered even by a multidimensional VLA with no constant bounds, like this one: void f (int n) { int a [n][n] = {{}}; }
*** Bug 71189 has been marked as a duplicate of this bug. ***
*** Bug 71593 has been marked as a duplicate of this bug. ***
Still happening with g++ (GCC) 8.1.1 20180531. The first sample from description gives x.cpp: In function 'void foo(int)': x.cpp:3:7: internal compiler error: in make_decl_rtl, at varasm.c:1322 int a[2][n] = {}; ^ Please submit a full bug report, with preprocessed source if appropriate. See <https://bugs.archlinux.org/> for instructions.
*** Bug 93730 has been marked as a duplicate of this bug. ***
Bisection of the first test case points to r198746 (GCC 4.9.0) as the first revision that started to ICE. Before then, GCC rejected the initialization with: pr58646.C: error: variable-sized object ‘a’ may not be initialized int a[2][n] = {}; ^ commit a57dbdaac40dbaaaba5b6d9954829a5e6f630ae4 Author: Jason Merrill <jason@redhat.com> Date: Thu May 9 12:43:43 2013 -0400 N3639 C++1y VLA diagnostics * decl.c (grokdeclarator): Complain about reference, pointer, or typedef to VLA. (create_array_type_for_decl): Complain about array of VLA. * pt.c (tsubst): Likewise. * rtti.c (get_tinfo_decl): Talk about "array of runtime bound". * semantics.c (finish_decltype_type): Complain about decltype of VLA. * typeck.c (cp_build_addr_expr_1): Complain about VLA. (cxx_sizeof_or_alignof_type): Likewise. From-SVN: r198746
GCC 8 branch is being closed.
GCC 9.4 is being released, retargeting bugs to GCC 9.5.
*** Bug 102406 has been marked as a duplicate of this bug. ***
*** Bug 98715 has been marked as a duplicate of this bug. ***
*** Bug 103918 has been marked as a duplicate of this bug. ***
*** Bug 104168 has been marked as a duplicate of this bug. ***
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>: https://gcc.gnu.org/g:c65bd532e225996cc9c5b75355d2cb648d0bcfc5 commit r12-7744-gc65bd532e225996cc9c5b75355d2cb648d0bcfc5 Author: Jason Merrill <jason@redhat.com> Date: Mon Mar 21 17:48:01 2022 -0400 c++: initialized array of vla [PR58646] We went into build_vec_init because we're dealing with a VLA, but then build_vec_init thought it was safe to just build an INIT_EXPR because the outer dimension is constant. Nope. PR c++/58646 gcc/cp/ChangeLog: * init.cc (build_vec_init): Check for vla element type. gcc/testsuite/ChangeLog: * g++.dg/ext/vla24.C: New test.
The releases/gcc-11 branch has been updated by Jason Merrill <jason@gcc.gnu.org>: https://gcc.gnu.org/g:09d0fc6912c4f600432caecc6ab0a277f2aef480 commit r11-9679-g09d0fc6912c4f600432caecc6ab0a277f2aef480 Author: Jason Merrill <jason@redhat.com> Date: Mon Mar 21 17:48:01 2022 -0400 c++: initialized array of vla [PR58646] We went into build_vec_init because we're dealing with a VLA, but then build_vec_init thought it was safe to just build an INIT_EXPR because the outer dimension is constant. Nope. PR c++/58646 gcc/cp/ChangeLog: * init.c (build_vec_init): Check for vla element type. gcc/testsuite/ChangeLog: * g++.dg/ext/vla24.C: New test.
GCC 9 branch is being closed
GCC 10.4 is being released, retargeting bugs to GCC 10.5.
Fixed in GCC 11.3.