[Bug middle-end/101290] ICE with -O1 on valid code: in maybe_canonicalize_mem_ref_addr, at gimple-fold.c:5976

2021-07-05 Thread joseph at codesourcery dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101290

--- Comment #2 from joseph at codesourcery dot com  ---
Anything constructing a constant-size type half the address space or 
larger in size should be diagnosed.

[Bug middle-end/101290] ICE with -O1 on valid code: in maybe_canonicalize_mem_ref_addr, at gimple-fold.c:5976

2021-07-02 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101290

Richard Biener  changed:

   What|Removed |Added

   Keywords||accepts-invalid
  Component|tree-optimization   |middle-end
 CC||jsm28 at gcc dot gnu.org
Version|tree-ssa|12.0

--- Comment #1 from Richard Biener  ---
We're asking get_addr_base_and_unit_offset on arg0 of

MEM[(volatile int *)[(struct  *)].f]

and the FIELD_DECL is

 
unit-size 
align:32 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0x76677e70
fields 
BLK t.c:56:7
size 
unit-size 
align:32 warn_if_not_align:0 offset_align 128
offset 
bit-offset  context
 chain > context

pointer_to_this  chain >
BLK t.c:57:11 size  unit-size 
align:32 warn_if_not_align:0 offset_align 32
offset  constant public overflow 10790227672893396768> bit-offset
 context >

and we hit

case COMPONENT_REF:
  {
tree field = TREE_OPERAND (exp, 1);
tree this_offset = component_ref_field_offset (exp);
poly_int64 hthis_offset;

if (!this_offset
|| !poly_int_tree_p (this_offset, _offset)
|| (TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (field))
% BITS_PER_UNIT))
  return NULL_TREE;

because this_offset doesn't fit the signed poly_int64.  IIRC we do have to
support negative field offsets.

Eventually this testcase is invalid since sizeof (*g) is bigger than half
of the address space.  Joseph?  We seem to happily wrap TYPE_SIZE[_UNIT]
even over the sizetype bounds without diagnosing anything - we do emit
some diagnostics from layout_type so that might be the place to complain
(we could then set TYPE_SIZE[_UNIT] to error_mark_node).

  constant public overflow 0x704ef12cb04cf1580>
unit-size  constant public overflow 16185341509340095152>