i -= wordsize;
continue;
}
- for (size_t j = i; j < i + wordsize && j < end; j++)
+ size_t endsize = end - i > wordsize ? wordsize : end - i;
+ for (size_t j = i; j < i + endsize; j++)
{
if (buf->buf[j])
{
if (padding_bytes)
{
if (nonzero_first == 0
- && nonzero_last == wordsize
+ && nonzero_last == endsize
&& all_ones)
{
/* All bits are padding and we had some padding
before too. Just extend it. */
- padding_bytes += wordsize;
+ padding_bytes += endsize;
continue;
}
if (all_ones && nonzero_first == 0)
if (nonzero_first == wordsize)
/* All bits in a word are 0, there are no padding bits. */
continue;
- if (all_ones && nonzero_last == wordsize)
+ if (all_ones && nonzero_last == endsize)
{
/* All bits between nonzero_first and end of word are padding
bits, start counting padding_bytes. */
j = k;
}
}
- if (nonzero_last == wordsize)
+ if (nonzero_last == endsize)
padding_bytes = nonzero_last - zero_last;
continue;
}
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;
--- /dev/null
+/* PR middle-end/115527 */
+/* { dg-do run } */
+
+struct T { struct S { double a; signed char b; long c; } d[3]; int e; } t1, t2;
+
+__attribute__((noipa)) void
+foo (struct T *t)
+{
+ for (int i = 0; i < 3; ++i)
+ {
+ t->d[i].a = 1. + 3 * i;
+ t->d[i].b = 2 + 3 * i;
+ t->d[i].c = 3 + 3 * i;
+ }
+ t->e = 10;
+}
+
+int
+main ()
+{
+ __builtin_memset (&t2, -1, sizeof (t2));
+ foo (&t1);
+ foo (&t2);
+ __builtin_clear_padding (&t2);
+ if (__builtin_memcmp (&t1, &t2, sizeof (t1)))
+ __builtin_abort ();
+ return 0;
+}