Bug 84424 - [8 Regression] ICE on C++ code: tree check: expected record_type or union_type or qual_union_type, have vector_type in reduced_constant_expression_p, at cp/constexpr.c:1766
Summary: [8 Regression] ICE on C++ code: tree check: expected record_type or union_typ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Jason Merrill
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2018-02-16 18:50 UTC by Zhendong Su
Modified: 2018-02-22 22:51 UTC (History)
4 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zhendong Su 2018-02-16 18:50:26 UTC
This seems to be a recent regression as the code is accepted by 7.2.0. 

$ g++tk -v
Using built-in specs.
COLLECT_GCC=g++tk
COLLECT_LTO_WRAPPER=/home/su/software/tmp/gcc/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/8.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-source-trunk/configure --enable-languages=c,c++,lto --prefix=/home/su/software/tmp/gcc/gcc-trunk --disable-bootstrap
Thread model: posix
gcc version 8.0.1 20180216 (experimental) [trunk revision 257739] (GCC)
$
$ g++-7.2.0 -c tmp.cpp
$
$ g++tk -c tmp.cpp
tmp.cpp:4:42: internal compiler error: tree check: expected record_type or union_type or qual_union_type, have vector_type in reduced_constant_expression_p, at cp/constexpr.c:1766
 constexpr vec v = __builtin_shuffle (v, u);
                                          ^
0x63cd06 tree_check_failed(tree_node const*, char const*, int, char const*, ...)
        ../../gcc-source-trunk/gcc/tree.c:9337
0x70aefc tree_check3(tree_node*, char const*, int, char const*, tree_code, tree_code, tree_code)
        ../../gcc-source-trunk/gcc/tree.h:3172
0x70aefc reduced_constant_expression_p(tree_node*)
        ../../gcc-source-trunk/gcc/cp/constexpr.c:1766
0x70af64 verify_constant
        ../../gcc-source-trunk/gcc/cp/constexpr.c:1809
0x71267b cxx_eval_trinary_expression
        ../../gcc-source-trunk/gcc/cp/constexpr.c:3378
0x71267b cxx_eval_constant_expression
        ../../gcc-source-trunk/gcc/cp/constexpr.c:4526
0x71954d cxx_eval_outermost_constant_expr
        ../../gcc-source-trunk/gcc/cp/constexpr.c:4801
0x92a5a2 store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>**, int)
        ../../gcc-source-trunk/gcc/cp/typeck2.c:833
0x750492 check_initializer
        ../../gcc-source-trunk/gcc/cp/decl.c:6378
0x778871 cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int)
        ../../gcc-source-trunk/gcc/cp/decl.c:7032
0x83428d cp_parser_init_declarator
        ../../gcc-source-trunk/gcc/cp/parser.c:19705
0x835f1f cp_parser_simple_declaration
        ../../gcc-source-trunk/gcc/cp/parser.c:13046
0x836e68 cp_parser_block_declaration
        ../../gcc-source-trunk/gcc/cp/parser.c:12864
0x842c84 cp_parser_declaration
        ../../gcc-source-trunk/gcc/cp/parser.c:12761
0x841606 cp_parser_declaration_seq_opt
        ../../gcc-source-trunk/gcc/cp/parser.c:12637
0x841923 cp_parser_translation_unit
        ../../gcc-source-trunk/gcc/cp/parser.c:4559
0x841923 c_parse_file()
        ../../gcc-source-trunk/gcc/cp/parser.c:38860
0x98a825 c_common_parse_file()
        ../../gcc-source-trunk/gcc/c-family/c-opts.c:1132
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
$


------------------------------------------------------------------


typedef int vec __attribute__ ((vector_size (2 * sizeof (int))));

constexpr vec u = { 1, 2 };
constexpr vec v = __builtin_shuffle (v, u);
Comment 1 Martin Sebor 2018-02-16 22:04:15 UTC
I can confirm it with r257668 but not with the top of trunk (r257768).  The regression was introduced in r251948.  I vaguely remember a bug with a test case similar to this one go by but I can't find it.  Can you please retry with a newer revision and report back?
Comment 2 Zhendong Su 2018-02-16 22:54:24 UTC
(In reply to Martin Sebor from comment #1)
> I can confirm it with r257668 but not with the top of trunk (r257768).  The
> regression was introduced in r251948.  I vaguely remember a bug with a test
> case similar to this one go by but I can't find it.  Can you please retry
> with a newer revision and report back?

My latest build is r257757, which still ICEs on this test. 

I am building the top of the trunk.
Comment 3 Jakub Jelinek 2018-02-16 23:51:42 UTC
I can reproduce with latest trunk too.
The ICE is on:
1765	      if (CONSTRUCTOR_NO_IMPLICIT_ZERO (t))
1766		field = next_initializable_field (TYPE_FIELDS (TREE_TYPE (t)));
1767	      else
1768		field = NULL_TREE;
where t is:
 <constructor 0x7fffefdb3228
    type <vector_type 0x7fffefd9f9d8 vec
        type <integer_type 0x7fffefc625e8 int public type_6 SI
            size <integer_cst 0x7fffefc650c0 constant 32>
            unit-size <integer_cst 0x7fffefc650d8 constant 4>
            align:32 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type 0x7fffefc625e8 precision:32 min <integer_cst 0x7fffefc65078 -2147483648> max <integer_cst 0x7fffefc65090 2147483647>
            pointer_to_this <pointer_type 0x7fffefc6aa80>>
        V2SI
        size <integer_cst 0x7fffefc45e70 constant 64>
        unit-size <integer_cst 0x7fffefc45e88 constant 8>
        align:64 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type 0x7fffefd72d20 nunits:2>
    constant tree_1 length:0>
created in:
4783	  if (AGGREGATE_TYPE_P (type) || VECTOR_TYPE_P (type))
4784	    {
4785	      /* In C++14 an NSDMI can participate in aggregate initialization,
4786		 and can refer to the address of the object being initialized, so
4787		 we need to pass in the relevant VAR_DECL if we want to do the
4788		 evaluation in a single pass.  The evaluation will dynamically
4789		 update ctx.values for the VAR_DECL.  We use the same strategy
4790		 for C++11 constexpr constructors that refer to the object being
4791		 initialized.  */
4792	      ctx.ctor = build_constructor (type, NULL);
4793	      CONSTRUCTOR_NO_IMPLICIT_ZERO (ctx.ctor) = true;

VECTOR_TYPE obviously doesn't have TYPE_FIELDS.

I guess we need to teach reduced_constant_expression_p how to handle VECTOR_TYPE constructors.
Comment 4 Jason Merrill 2018-02-22 22:51:02 UTC
Fixed.
Comment 5 Jason Merrill 2018-02-22 22:51:12 UTC
Author: jason
Date: Thu Feb 22 22:50:37 2018
New Revision: 257924

URL: https://gcc.gnu.org/viewcvs?rev=257924&root=gcc&view=rev
Log:
	PR c++/84424 - ICE with constexpr and __builtin_shuffle.

	* constexpr.c (reduced_constant_expression_p): Handle CONSTRUCTOR of
	VECTOR_TYPE.

Added:
    trunk/gcc/testsuite/g++.dg/ext/vector34.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/constexpr.c