https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95493
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |ASSIGNED Assignee|unassigned at gcc dot gnu.org |rguenth at gcc dot gnu.org --- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> --- OK, so the issue is we're getting these MEM_ATTRs when expanding the base as (mem/c:V4SI (plus:DI (reg/f:DI 77 virtual-stack-vars) (const_int -32 [0xffffffffffffffe0])) [5 MEM[(struct ._anon_0 *)_42]+0 S16 A128]) and set_mem_attributes_minus_bitpos due to the variable array-ref wouldn't assign any here but inherits the already set ones. /* Default values from pre-existing memory attributes if present. */ refattrs = MEM_ATTRS (ref); if (refattrs) { /* ??? Can this ever happen? Calling this routine on a MEM that already carries memory attributes should probably be invalid. */ attrs.expr = refattrs->expr; attrs.offset_known_p = refattrs->offset_known_p; attrs.offset = refattrs->offset; attrs.size_known_p = refattrs->size_known_p; attrs.size = refattrs->size; attrs.align = refattrs->align; } so the following fixes the issue, the MEM_ATTRs are not what the code expects them to be set with otherwise. Because clearly offset_known_p should be false. diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c index 2b790636366..0a72269e2ce 100644 --- a/gcc/emit-rtl.c +++ b/gcc/emit-rtl.c @@ -2114,6 +2114,10 @@ set_mem_attributes_minus_bitpos (rtx ref, tree t, int objectp, } while (TREE_CODE (t2) == ARRAY_REF); + attrs.expr = NULL_TREE; + attrs.offset_known_p = false; + attrs.offset = 0; + apply_bitpos = 0; if (DECL_P (t2) || (TREE_CODE (t2) == COMPONENT_REF /* For trailing arrays t2 doesn't have a size that