Bug 58646 - [10/11 Regression] ICE on a multidimensional VLA with an empty initializer list
Summary: [10/11 Regression] ICE on a multidimensional VLA with an empty initializer list
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.9.0
: P2 normal
Target Milestone: 11.3
Assignee: Jason Merrill
URL:
Keywords: ice-on-invalid-code
: 71189 71593 93730 98715 102406 103918 104168 (view as bug list)
Depends on:
Blocks: C++VLA
  Show dependency treegraph
 
Reported: 2013-10-06 20:32 UTC by Volker Reichelt
Modified: 2024-01-01 03:32 UTC (History)
10 users (show)

See Also:
Host:
Target:
Build:
Known to work: 11.3.0, 12.0, 4.8.5
Known to fail: 10.0, 10.5.0, 4.9.4, 5.5.0, 6.4.0, 7.2.0, 8.0, 9.2.0
Last reconfirmed: 2016-03-06 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2013-10-06 20:32:22 UTC
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.]
Comment 1 Volker Reichelt 2013-10-06 20:36:08 UTC
Jason, you did some VLA related work for c++1y.
Would you mind having a look? Thanks!
Comment 2 Marek Polacek 2013-10-07 11:44:42 UTC
All of them are probably related to r198745 (N3639 C++1y VLA support).
Comment 3 Martin Sebor 2016-03-06 18:03:19 UTC
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.
Comment 4 Martin Sebor 2016-03-30 21:43:42 UTC
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.
Comment 5 Martin Sebor 2016-03-30 22:31:09 UTC
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] = {{}};
}
Comment 6 Martin Sebor 2016-05-19 01:11:27 UTC
*** Bug 71189 has been marked as a duplicate of this bug. ***
Comment 7 Martin Sebor 2016-06-20 16:59:36 UTC
*** Bug 71593 has been marked as a duplicate of this bug. ***
Comment 8 Andrey Vihrov 2018-06-12 15:32:12 UTC
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.
Comment 9 Martin Sebor 2020-02-17 16:35:46 UTC
*** Bug 93730 has been marked as a duplicate of this bug. ***
Comment 10 Martin Sebor 2020-02-17 16:40:14 UTC
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
Comment 11 Jakub Jelinek 2021-05-14 09:46:56 UTC
GCC 8 branch is being closed.
Comment 12 Richard Biener 2021-06-01 08:06:04 UTC
GCC 9.4 is being released, retargeting bugs to GCC 9.5.
Comment 13 Andrew Pinski 2021-09-19 17:33:13 UTC
*** Bug 102406 has been marked as a duplicate of this bug. ***
Comment 14 Andrew Pinski 2021-10-01 07:16:09 UTC
*** Bug 98715 has been marked as a duplicate of this bug. ***
Comment 15 Andrew Pinski 2022-01-05 11:14:44 UTC
*** Bug 103918 has been marked as a duplicate of this bug. ***
Comment 16 Andrew Pinski 2022-01-21 17:48:43 UTC
*** Bug 104168 has been marked as a duplicate of this bug. ***
Comment 17 GCC Commits 2022-03-21 22:25:41 UTC
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.
Comment 18 GCC Commits 2022-03-22 05:18:11 UTC
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.
Comment 19 Richard Biener 2022-05-27 09:34:59 UTC
GCC 9 branch is being closed
Comment 20 Jakub Jelinek 2022-06-28 10:30:40 UTC
GCC 10.4 is being released, retargeting bugs to GCC 10.5.
Comment 21 Richard Biener 2023-07-07 07:22:26 UTC
Fixed in GCC 11.3.