From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 223493857410; Tue, 19 Jul 2022 11:38:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 223493857410 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-8579] tree-optimization/105969 - FPE with array diagnostics X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: 1fe7321a6ce0dcb05763c8f1850a066824516342 X-Git-Newrev: 4f34a9e8d5ffcef99a212180d58718b00bdbb7d2 Message-Id: <20220719113808.223493857410@sourceware.org> Date: Tue, 19 Jul 2022 11:38:08 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Jul 2022 11:38:08 -0000 https://gcc.gnu.org/g:4f34a9e8d5ffcef99a212180d58718b00bdbb7d2 commit r12-8579-g4f34a9e8d5ffcef99a212180d58718b00bdbb7d2 Author: Richard Biener 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 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. (cherry picked from commit edb9330c29fe8a0a0b76df6fafd6a223a4d0e41f) 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 9bd17bcca92..c0405ab32db 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 } */ +}