https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115527
--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to qinzhao from comment #6)
> --- a/gcc/gimple-fold.cc
> +++ b/gcc/gimple-fold.cc
> @@ -4815,6 +4815,7 @@ clear_padding_type (clear_padding_struct *buf, tree
> type,
> unsigned int prev_align = buf->align;
> HOST_WIDE_INT off = buf->off + buf->size;
> HOST_WIDE_INT prev_sz = buf->sz;
> + HOST_WIDE_INT prev_size = buf->size;
> clear_padding_flush (buf, true);
> tree elttype = TREE_TYPE (type);
> buf->base = create_tmp_var (build_pointer_type (elttype));
> @@ -4835,8 +4836,8 @@ clear_padding_type (clear_padding_struct *buf, tree
> type,
> buf->base = base;
> buf->sz = prev_sz;
> buf->align = prev_align;
> - buf->size = off % UNITS_PER_WORD;
> - buf->off = off - buf->size;
> + buf->size = prev_size + nelts * fldsz;
> + buf->off = 0;
> memset (buf->buf, 0, buf->size);
> break;
> }
That is incorrect.
I think the right fix is
--- gcc/gimple-fold.cc.jj 2024-07-16 13:36:36.000000000 +0200
+++ gcc/gimple-fold.cc 2024-07-16 15:50:26.493782065 +0200
@@ -4832,6 +4832,7 @@ clear_padding_type (clear_padding_struct
buf->off = 0;
buf->size = 0;
clear_padding_emit_loop (buf, elttype, end, for_auto_init);
+ off += sz;
buf->base = base;
buf->sz = prev_sz;
buf->align = prev_align;
Will try to test it soon.