From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1285) id 147E33858C55; Thu, 13 Oct 2022 23:02:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 147E33858C55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665702152; bh=jR4dfA1D5EM/GoDjwSWQU68SdQk69V0i98UATW8RMlc=; h=From:To:Subject:Date:From; b=BH0L7//5uLsTV8y/rPA5lmOugFScI+Ac9BThdSCCKF8wspkOvHD9vfcWZKQPFT+ac CrISIRgC2XoeFfAoTARvJBfV+EMkfPgPi1tUSSeHW+cpkSyMLwIQAKk0I6hSNqSX0X slJvit/1kKmwH6YEkfmvObHFAYJykrS+Jo12Aj2Y= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Eric Botcazou To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3287] Fix bogus -Wstringop-overflow warning X-Act-Checkin: gcc X-Git-Author: Eric Botcazou X-Git-Refname: refs/heads/master X-Git-Oldrev: 537e08cfad04e79fb97d368e397cfc7e782865ec X-Git-Newrev: c26d335fffc689051ee5826455c9d54d1fcf1816 Message-Id: <20221013230232.147E33858C55@sourceware.org> Date: Thu, 13 Oct 2022 23:02:32 +0000 (GMT) List-Id: https://gcc.gnu.org/g:c26d335fffc689051ee5826455c9d54d1fcf1816 commit r13-3287-gc26d335fffc689051ee5826455c9d54d1fcf1816 Author: Eric Botcazou Date: Fri Oct 14 00:55:40 2022 +0200 Fix bogus -Wstringop-overflow warning If you compile the testcase with -O2 -fno-inline -Wall, you get: In function 'process_array3': cc1: warning: 'process_array4' accessing 4 bytes in a region of size 3 [- Wstringop-overflow=] cc1: note: referencing argument 1 of type 'char[4]' t.c:6:6: note: in a call to function 'process_array4' 6 | void process_array4 (char a[4], int n) | ^~~~~~~~~~~~~~ cc1: warning: 'process_array4' accessing 4 bytes in a region of size 3 [- Wstringop-overflow=] cc1: note: referencing argument 1 of type 'char[4]' t.c:6:6: note: in a call to function 'process_array4' That's because the ICF IPA pass has identified the two functions and turned process_array3 into a wrapper of process_array4. gcc/ * gimple-ssa-warn-access.cc (pass_waccess::check_call): Return early for calls made from thunks. gcc/testsuite/ * gcc.dg/Wstringop-overflow-89.c: New test. Diff: --- gcc/gimple-ssa-warn-access.cc | 8 ++++++-- gcc/testsuite/gcc.dg/Wstringop-overflow-89.c | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc index 04aa849a4b1..59a70530600 100644 --- a/gcc/gimple-ssa-warn-access.cc +++ b/gcc/gimple-ssa-warn-access.cc @@ -4291,14 +4291,18 @@ pass_waccess::check_pointer_uses (gimple *stmt, tree ptr, void pass_waccess::check_call (gcall *stmt) { - if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL)) - check_builtin (stmt); + /* Skip special calls generated by the compiler. */ + if (gimple_call_from_thunk_p (stmt)) + return; /* .ASAN_MARK doesn't access any vars, only modifies shadow memory. */ if (gimple_call_internal_p (stmt) && gimple_call_internal_fn (stmt) == IFN_ASAN_MARK) return; + if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL)) + check_builtin (stmt); + if (!m_early_checks_p) if (tree callee = gimple_call_fndecl (stmt)) { diff --git a/gcc/testsuite/gcc.dg/Wstringop-overflow-89.c b/gcc/testsuite/gcc.dg/Wstringop-overflow-89.c new file mode 100644 index 00000000000..ba25a9386a7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wstringop-overflow-89.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-inline -Wall" } */ + +extern void process (char); + +void process_array4 (char a[4], int n) +{ + for (int i = 0; i < n; i++) + process (a[i]); +} + +void process_array3 (char a[3], int n) +{ + for (int i = 0; i < n; i++) + process (a[i]); +}