public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-1105] tree-optimization/105969 - FPE with array diagnostics Date: Wed, 15 Jun 2022 11:15:22 +0000 (GMT) [thread overview] Message-ID: <20220615111522.168E83841441@sourceware.org> (raw) https://gcc.gnu.org/g:edb9330c29fe8a0a0b76df6fafd6a223a4d0e41f commit r13-1105-gedb9330c29fe8a0a0b76df6fafd6a223a4d0e41f Author: Richard Biener <rguenther@suse.de> Date: Wed Jun 15 10:54:48 2022 +0200 tree-optimization/105969 - FPE with array diagnostics For a [0][0] array we have to be careful when dividing by the element size which is zero for the outermost dimension. Luckily the division is only for an overflow check which is pointless for array size zero. 2022-06-15 Richard Biener <rguenther@suse.de> PR tree-optimization/105969 * gimple-ssa-sprintf.cc (get_origin_and_offset_r): Avoid division by zero in overflow check. * gcc.dg/pr105969.c: New testcase. Diff: --- gcc/gimple-ssa-sprintf.cc | 2 +- gcc/testsuite/gcc.dg/pr105969.c | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/gcc/gimple-ssa-sprintf.cc b/gcc/gimple-ssa-sprintf.cc index 6bd27302213..a888b5ac7d5 100644 --- a/gcc/gimple-ssa-sprintf.cc +++ b/gcc/gimple-ssa-sprintf.cc @@ -2319,7 +2319,7 @@ get_origin_and_offset_r (tree x, HOST_WIDE_INT *fldoff, HOST_WIDE_INT *fldsize, if (byteoff < HOST_WIDE_INT_MAX && elbytes < HOST_WIDE_INT_MAX - && byteoff / elbytes == idx) + && (elbytes == 0 || byteoff / elbytes == idx)) { /* For in-bounds constant offsets into constant-sized arrays bump up *OFF, and for what's likely arrays or structs of diff --git a/gcc/testsuite/gcc.dg/pr105969.c b/gcc/testsuite/gcc.dg/pr105969.c new file mode 100644 index 00000000000..52c63fc2efe --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr105969.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-Wall" } */ + +struct A +{ + char a[0][0][0]; +}; +extern struct A b[][2]; +void f (void) +{ + __builtin_sprintf (b[0][0].a[1][0], "%s", b[0][0].a[1][0]); /* { dg-warning "past the end" } */ + /* { dg-warning "overlaps destination" "" { target *-*-* } .-1 } */ +}
reply other threads:[~2022-06-15 11:15 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20220615111522.168E83841441@sourceware.org \ --to=rguenth@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /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: linkBe 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).