https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96591

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
So the type is refered to by constant 8 which is refered to by a VECTOR_CST
{ 8 } which is refered to by

# .MEM_4 = VDEF <.MEM_2>
MEM[(struct Test *)_3].data[0] = { 8 };

and while walk_tree walks CTOR elements for VECTOR_CST it does nothing:

  switch (code)
    {
    case ERROR_MARK:
    case IDENTIFIER_NODE:
    case INTEGER_CST:
    case REAL_CST:
    case FIXED_CST:
    case VECTOR_CST:
    case STRING_CST:
    case BLOCK:
    case PLACEHOLDER_EXPR:
    case SSA_NAME:
    case FIELD_DECL:
    case RESULT_DECL:
      /* None of these have subtrees other than those already walked
         above.  */
      break;

which is eventually true since we expect the element type of a VECTOR_CST
to match that of the vector element type.  _But_ - we're forcing a vector
element type to be the main variant / canonical type:

 <vector_cst 0x7ffff66d9c30
    type <vector_type 0x7ffff66dedc8
        type <integer_type 0x7ffff65885e8 int public type_6 SI
            size <integer_cst 0x7ffff658b108 constant 32>
            unit-size <integer_cst 0x7ffff658b120 constant 4>
            align:32 warn_if_not_align:0 symtab:0 alias-set 2 canonical-type
0x7ffff65885e8 precision:32 min <integer_cst 0x7ffff658b0c0 -2147483648> max
<integer_cst 0x7ffff658b0d8 2147483647>
            pointer_to_this <pointer_type 0x7ffff65909d8>>
        type_6 SI size <integer_cst 0x7ffff658b108 32> unit-size <integer_cst
0x7ffff658b120 4>
        align:32 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0x7ffff66dedc8 nunits:1>
    constant npatterns:1 nelts-per-pattern:1
    elt:0:  <integer_cst 0x7ffff66d9be8 type <integer_type 0x7ffff66de3f0
scalar_type> constant 8>>
(gdb) p ((tree)0x7ffff66de3f0)->type_common.canonical 
$134 = <integer_type 0x7ffff65885e8 int>
(gdb) p ((tree)0x7ffff66de3f0)->type_common.main_variant 
$135 = <integer_type 0x7ffff65885e8 int>

where we build this via

#0  0x0000000001cf4437 in tree_vector_builder::build (this=0x7fffffffbfe0)
    at /home/rguenther/src/gcc3/gcc/tree-vector-builder.c:44
#1  0x0000000001d112c9 in build_vector_from_ctor (
    type=<vector_type 0x7ffff66dedc8>, v=0x7ffff66e72d0 = {...})
    at /home/rguenther/src/gcc3/gcc/tree.c:1969
#2  0x00000000012cccda in fold (expr=<constructor 0x7ffff66d9c18>)
    at /home/rguenther/src/gcc3/gcc/fold-const.c:13383
#3  0x0000000000b0b893 in cxx_eval_bare_aggregate (ctx=0x7fffffffc290, 
    t=<constructor 0x7ffff66d9c18>, lval=false, non_constant_p=0x7fffffffd1bf, 
    overflow_p=0x7fffffffd1be)
    at /home/rguenther/src/gcc3/gcc/cp/constexpr.c:4438
#4  0x0000000000b14c6b in cxx_eval_constant_expression (ctx=0x7fffffffc610, 
    t=<constructor 0x7ffff66d9bd0>, lval=false, non_constant_p=0x7fffffffd1bf, 
    overflow_p=0x7fffffffd1be, jump_target=0x0)
    at /home/rguenther/src/gcc3/gcc/cp/constexpr.c:6591

it's tempting to try force the cached integer constants to be always
unqualified so that only the TYPE_MAIN_VARIANT has TYPE_CACHED_VALUES
and we save memory.  The constant is built via

(gdb) bt
#0  0x0000000001d0fcf1 in cache_wide_int_in_type_cache (
    type=<integer_type 0x7ffff66de3f0 scalar_type>, cst=..., slot=9, 
    max_slots=252) at /home/rguenther/src/gcc3/gcc/tree.c:1535
#1  0x0000000001d1020d in wide_int_to_tree_1 (
    type=<integer_type 0x7ffff66de3f0 scalar_type>, pcst=...)
    at /home/rguenther/src/gcc3/gcc/tree.c:1649
#2  0x0000000001d10878 in wide_int_to_tree (
    type=<integer_type 0x7ffff66de3f0 scalar_type>, value=...)
    at /home/rguenther/src/gcc3/gcc/tree.c:1756
#3  0x0000000001d0f918 in force_fit_type (
    type=<integer_type 0x7ffff66de3f0 scalar_type>, cst=..., overflowable=1, 
    overflowed=false) at /home/rguenther/src/gcc3/gcc/tree.c:1474
#4  0x00000000012969cb in fold_convert_const_int_from_int (
    type=<integer_type 0x7ffff66de3f0 scalar_type>, 
    arg1=<integer_cst 0x7ffff66d9618>)
    at /home/rguenther/src/gcc3/gcc/fold-const.c:2000
#5  0x00000000012988b6 in fold_convert_const (code=NOP_EXPR, 
    type=<integer_type 0x7ffff66de3f0 scalar_type>, 
    arg1=<integer_cst 0x7ffff66d9618>)
    at /home/rguenther/src/gcc3/gcc/fold-const.c:2276
#6  0x0000000001299214 in fold_convert_loc (loc=0, 
    type=<integer_type 0x7ffff66de3f0 scalar_type>, 
    arg=<integer_cst 0x7ffff66d9618>)
--Type <RET> for more, q to quit, c to continue without paging--
    at /home/rguenther/src/gcc3/gcc/fold-const.c:2418
#7  0x0000000000b714fa in cp_fold_convert (
    type=<integer_type 0x7ffff66de3f0 scalar_type>, 
    expr=<integer_cst 0x7ffff66d9618>)
    at /home/rguenther/src/gcc3/gcc/cp/cvt.c:629
#8  0x0000000000aff0d3 in adjust_temp_type (
    type=<integer_type 0x7ffff66de888 scalar_type>, 
    temp=<integer_cst 0x7ffff66d9618>)
    at /home/rguenther/src/gcc3/gcc/cp/constexpr.c:1501
#9  0x0000000000aff651 in cxx_bind_parameters_in_call (ctx=0x7fffffffd0a0, 
    t=<call_expr 0x7ffff6577150>, new_call=0x7fffffffccc0, 
    non_constant_p=0x7fffffffd1bf, overflow_p=0x7fffffffd1be, 
    non_constant_args=0x7fffffffcc7f)
    at /home/rguenther/src/gcc3/gcc/cp/constexpr.c:1611
#10 0x0000000000b0404c in cxx_eval_call_expression (ctx=0x7fffffffd0a0, 
    t=<call_expr 0x7ffff6577150>, lval=false, non_constant_p=0x7fffffffd1bf, 
    overflow_p=0x7fffffffd1be)
    at /home/rguenther/src/gcc3/gcc/cp/constexpr.c:2536
#11 0x0000000000b13215 in cxx_eval_constant_expression (ctx=0x7fffffffd0a0, 
    t=<call_expr 0x7ffff6577150>, lval=false, non_constant_p=0x7fffffffd1bf, 
    overflow_p=0x7fffffffd1be, jump_target=0x0)
    at /home/rguenther/src/gcc3/gcc/cp/constexpr.c:6134

where the constant is first built in the "correct" type and then
converted via adjust_temp_type which does

1499      /* Now we know we're dealing with a scalar, and a prvalue of
non-class
1500         type is cv-unqualified.  */
1501      return cp_fold_convert (cv_unqualified (type), temp);

but that cv_unqualified doesn't produce the main variant.

Now, as a fact walk_tree _does_ walk COMPLEX_CST components so the "obvious"
fix here would be to change it to also walk VECTOR_CST components.  So that's
what I'm going to try first.

Reply via email to