Bug 69253 - [6 Regression] ICE in cxx_incomplete_type_diagnostic initializing a flexible array member with empty string
Summary: [6 Regression] ICE in cxx_incomplete_type_diagnostic initializing a flexible ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 6.0
: P1 normal
Target Milestone: 6.0
Assignee: Martin Sebor
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2016-01-12 19:40 UTC by Qirun Zhang
Modified: 2018-09-22 03:25 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 6.0
Last reconfirmed: 2016-01-12 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Qirun Zhang 2016-01-12 19:40:34 UTC
The following code causes an ICE when compiled with the current g++ trunk at -O0  on x86_64-linux-gnu in both 32-bit and 64-bit modes.

Please note that g++ with -O1 and above compiles the code snippet. Should g++ allow the initialization of flexible array members?




$ g++-trunk -v
Using built-in specs.
COLLECT_GCC=g++-trunk
COLLECT_LTO_WRAPPER=/home/absozero/trunk/root-gcc/libexec/gcc/x86_64-pc-linux-gnu/6.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --prefix=/home/absozero/trunk/root-gcc --enable-languages=c,c++ --disable-werror --enable-multilib
Thread model: posix
gcc version 6.0.0 20160112 (experimental) [trunk revision 232269] (GCC)



$ g++-trunk  -O0 -c abc.cc
abc.cc: In function 'void fn1()':
abc.cc:5:33: internal compiler error: in cxx_incomplete_type_diagnostic, at cp/typeck2.c:567
 void fn1() { (struct str){1, ""}; }
                                 ^

0x6c53cf cxx_incomplete_type_diagnostic(tree_node const*, tree_node const*, diagnostic_t)
	../../gcc/gcc/cp/typeck2.c:567
0xf863fa size_in_bytes(tree_node const*)
	../../gcc/gcc/tree.c:2925
0xa1369c int_expr_size
	../../gcc/gcc/expr.c:11639
0xa2709a store_expr_with_bounds(tree_node*, rtx_def*, int, bool, bool, tree_node*)
	../../gcc/gcc/expr.c:5360
0xa28821 expand_assignment(tree_node*, tree_node*, bool)
	../../gcc/gcc/expr.c:5021
0x91a9be expand_gimple_stmt_1
	../../gcc/gcc/cfgexpand.c:3606
0x91a9be expand_gimple_stmt
	../../gcc/gcc/cfgexpand.c:3702
0x91e0a4 expand_gimple_basic_block
	../../gcc/gcc/cfgexpand.c:5708
0x923076 execute
	../../gcc/gcc/cfgexpand.c:6323
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.


------------------
$ cat abc.cc
struct str {
  int a;
  char s[];
};
void fn1() { (struct str){1, ""}; }
Comment 1 Marek Polacek 2016-01-12 19:54:24 UTC
Started with r231665.
Comment 2 Martin Sebor 2016-01-12 23:24:34 UTC
I don't think the code is valid.  It's rejected in C mode with the error below, and since flexible array members are a G++ extension provided for compatibility with GCC, it should also be rejected in C++ mode.  That g++ versions before 6.0 accepted this and other invalid constructs involving flexible array members was unintentional (and was fixed in r231665).

gcc-69253.C:5:30: error: non-static initialization of a flexible array member
 void fn1() { (struct str){1, ""}; }
                              ^~

That said, the ICE needs to be fixed.  Let me take care of that.
Comment 3 Martin Sebor 2016-01-18 19:41:32 UTC
Oddly, the following slightly modified test case is accepted and doesn't ICE:

struct A { char i, a []; };

void foo () {
    (struct A){ 1, "" };
}
Comment 4 Martin Sebor 2016-01-18 19:57:26 UTC
Patch posted for review:
https://gcc.gnu.org/ml/gcc-patches/2016-01/msg01325.html
Comment 5 Martin Sebor 2016-02-04 04:51:14 UTC
Author: msebor
Date: Thu Feb  4 04:50:42 2016
New Revision: 233126

URL: https://gcc.gnu.org/viewcvs?rev=233126&root=gcc&view=rev
Log:
PR c++/69251 - [6 Regression] ICE in unify_array_domain on a flexible array
               member
PR c++/69253 - [6 Regression] ICE in cxx_incomplete_type_diagnostic initializing
               a flexible array member with empty string
PR c++/69290 - [6 Regression] ICE on invalid initialization of a flexible array
               member
PR c++/69277 - [6 Regression] ICE mangling a flexible array member
PR c++/69349 - template substitution error for flexible array members

gcc/testsuite/ChangeLog:
2016-02-03  Martin Sebor  <msebor@redhat.com>

	PR c++/69251
	PR c++/69253
	PR c++/69290
	PR c++/69277
	PR c++/69349
	* g++.dg/ext/flexarray-mangle-2.C: New test.
	* g++.dg/ext/flexarray-mangle.C: New test.
	* g++.dg/ext/flexarray-subst.C: New test.
	* g++.dg/ext/flexary11.C: New test.
	* g++.dg/ext/flexary12.C: New test.
	* g++.dg/ext/flexary13.C: New test.
	* g++.dg/ext/flexary14.C: New test.
	* g++.dg/other/dump-ada-spec-2.C: Adjust.

gcc/cp/ChangeLog:
2016-02-03  Martain Sebor  <msebor@redhat.com>

	PR c++/69251
	PR c++/69253
	PR c++/69290
	PR c++/69277
	PR c++/69349
	* class.c (walk_subobject_offsets): Avoid testing the upper bound
	of a flexible array member for equality to null.
	(find_flexarrays): Remove spurious whitespace introduced in r231665.
	(diagnose_flexarrays): Avoid checking the upper bound of arrays.
	(check_flexarrays): Same.
	* decl.c (compute_array_index_type): Avoid special case for flexible
	array members.
	(grokdeclarator): Avoid calling compute_array_index_type for flexible
	array members.
	* error.c (dump_type_suffix): Revert changes introduced in r231665
	and rendered unnecessary by the changes above.
	* pt.c (tsubst):  Same.
	* tree.c (build_ctor_subob_ref): Handle flexible array members.
	* typeck2.c (digest_init_r): Revert changes introduced in r231665.
	(process_init_constructor_array): Same.
	(process_init_constructor_record): Same.

Added:
    trunk/gcc/testsuite/g++.dg/ext/flexarray-mangle-2.C
    trunk/gcc/testsuite/g++.dg/ext/flexarray-mangle.C
    trunk/gcc/testsuite/g++.dg/ext/flexarray-subst.C
    trunk/gcc/testsuite/g++.dg/ext/flexary11.C
    trunk/gcc/testsuite/g++.dg/ext/flexary12.C
    trunk/gcc/testsuite/g++.dg/ext/flexary13.C
    trunk/gcc/testsuite/g++.dg/ext/flexary14.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/class.c
    trunk/gcc/cp/decl.c
    trunk/gcc/cp/error.c
    trunk/gcc/cp/mangle.c
    trunk/gcc/cp/pt.c
    trunk/gcc/cp/tree.c
    trunk/gcc/cp/typeck2.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/other/dump-ada-spec-2.C
Comment 6 Martin Sebor 2016-02-04 04:52:00 UTC
Fixed.