[Bug middle-end/103839] __builtin_clear_padding doesn't zero alignment holes of unions with fields that overlap padding

ibuclaw at gdcproject dot org gcc-bugzilla@gcc.gnu.org
Sun Dec 26 18:04:19 GMT 2021


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

--- Comment #1 from Iain Buclaw <ibuclaw at gdcproject dot org> ---
(In reply to Iain Buclaw from comment #0)
> I can work around this by setting DECL_PADDING_P on all fields in unions
> except the first.  However I suspect this is a mistake, and the proper thing
> to do would be to only consider the first field when clear padding a union.
The fix to do this being a one-liner in gimple-fold.c

diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index 64515aabc04..9426e9ca473 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -4537,6 +4537,7 @@ clear_padding_union (clear_padding_struct *buf, tree
type,
        clear_padding_type (union_buf, TREE_TYPE (field), fldsz,
for_auto_init);
        clear_padding_add_padding (union_buf, sz - fldsz);
        clear_padding_flush (union_buf, true);
+       break;
       }

   if (buf == union_buf)


More information about the Gcc-bugs mailing list