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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org

--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
So we have two "unsigned char [7]" types.  They are the same except that one
has TYPE_DEPENDENT_P_VALID set.

One of them comes from the C++ FE: grokfield -> grokdeclarator ->
create_array_type_for_decl etc.  This has TYPE_DEPENDENT_P_VALID set.

The other one is created in gimple_fold_builtin_memory_op:

1323           desttype = build_array_type_nelts (unsigned_char_type_node,
1324                                              tree_to_uhwi (len));
1325           srctype = desttype;
1326           if (src_align > TYPE_ALIGN (srctype))
1327             srctype = build_aligned_type (srctype, src_align);
1328           srcvar = fold_build2 (MEM_REF, srctype, src, off0);

this also answers the question why the problem only happens with "unsigned
char".

Later, we warn in maybe_warn_operand: warning_at -> ... -> print_mem_ref which
tries to display:

  MEM <unsigned char[7]> [(char * {ref-all})&D.2870 + 1B]

print_mem_ref calls c_fold_indirect_ref_for_warn with this:

1961                 tree cop = build3_loc (loc, COMPONENT_REF, TREE_TYPE
(field),
1962                                        op, field, NULL_TREE);
1963                 off = off - upos;
1964                 if (tree ret = c_fold_indirect_ref_for_warn (loc, type,
cop,
1965                                                              off))
1966                   return ret;

The type of the MEM_REF is the second type.  But COP here is D.2870.pad, and
its type is the first one.  Comparing those two in
same_type_ignoring_top_level_qualifiers_p will crash since they are the same
types but their canonical types are not identical.

I don't know what the fix would be.

Reply via email to