From: Martin Liska Date: Wed, 2 Dec 2020 08:44:40 +0000 (+0100) Subject: Fix __builtin_clear_padding for empty struct. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=337d6362458ab033d3bfe287dda37f9da5577406;p=gcc.git Fix __builtin_clear_padding for empty struct. gcc/ChangeLog: PR c/98087 * gimple-fold.c (clear_padding_type): Do not divide by zero. gcc/testsuite/ChangeLog: PR c/98087 * gcc.c-torture/compile/pr98087.c: New test. --- diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 1f3d80e2881..ab74494703a 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -4552,6 +4552,8 @@ clear_padding_type (clear_padding_struct *buf, tree type, HOST_WIDE_INT sz) case ARRAY_TYPE: HOST_WIDE_INT nelts, fldsz; fldsz = int_size_in_bytes (TREE_TYPE (type)); + if (fldsz == 0) + break; nelts = sz / fldsz; if (nelts > 1 && sz > 8 * UNITS_PER_WORD diff --git a/gcc/testsuite/gcc.c-torture/compile/pr98087.c b/gcc/testsuite/gcc.c-torture/compile/pr98087.c new file mode 100644 index 00000000000..8cac770aa14 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr98087.c @@ -0,0 +1,14 @@ +/* PR c/98087 */ + +struct S { char a; long long b; }; +struct T { struct S c[0]; char d; }; +void foo (int n) +{ + struct S a[n][0]; + __builtin_clear_padding (a); + __builtin_clear_padding (&a); + struct S b[7][0]; + __builtin_clear_padding (&b); + struct T c; + __builtin_clear_padding (&c); +}