From: "Martin Liška" <mliska@suse.cz>
To: gcc-patches@gcc.gnu.org
Cc: Jakub Jelinek <jakub@redhat.com>
Subject: [PATCH] Fix __builtin_clear_padding for empty struct.
Date: Wed, 2 Dec 2020 10:25:32 +0100 [thread overview]
Message-ID: <730211eb-43b3-aa04-dc66-22f53b715b88@suse.cz> (raw)
It's a simple fix of a division by zero.
Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
Ready to be installed?
Thanks,
Martin
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.
---
gcc/gimple-fold.c | 2 ++
gcc/testsuite/gcc.c-torture/compile/pr98087.c | 8 ++++++++
2 files changed, 10 insertions(+)
create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr98087.c
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..9f0e5c4be7d
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr98087.c
@@ -0,0 +1,8 @@
+/* PR c/98087 */
+
+struct S {};
+void foo (int n)
+{
+ struct S a[n][0];
+ __builtin_clear_padding (a);
+}
--
2.29.2
next reply other threads:[~2020-12-02 9:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-02 9:25 Martin Liška [this message]
2020-12-02 10:11 ` Jakub Jelinek
2020-12-02 10:32 ` Martin Liška
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=730211eb-43b3-aa04-dc66-22f53b715b88@suse.cz \
--to=mliska@suse.cz \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).