From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 892443857C52; Tue, 18 Jan 2022 13:33:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 892443857C52 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-6672] tree-optimization/103987 - guard DSE modref query X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: 4288b57affe34fbc60badf798eb0c19892e69980 X-Git-Newrev: 3ed40db0f12994e64434dc2e0590ba1da7ba5f60 Message-Id: <20220118133327.892443857C52@sourceware.org> Date: Tue, 18 Jan 2022 13:33:27 +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, 18 Jan 2022 13:33:27 -0000 https://gcc.gnu.org/g:3ed40db0f12994e64434dc2e0590ba1da7ba5f60 commit r12-6672-g3ed40db0f12994e64434dc2e0590ba1da7ba5f60 Author: Richard Biener Date: Tue Jan 18 13:26:22 2022 +0100 tree-optimization/103987 - guard DSE modref query This adds a missing guard for a pointer to the DSE modref query, otherwise we can end up invoking APIs desired to only work on pointers on non-pointers when there are mismatches between declared and actual arguments of functions in the program. 2022-01-18 Richard Biener PR tree-optimization/103987 * tree-ssa-dse.cc (dse_optimize_call): Properly guard modref query with a pointer check. * gcc.dg/torture/pr103987.c: New testcase. Diff: --- gcc/testsuite/gcc.dg/torture/pr103987.c | 13 +++++++++++++ gcc/tree-ssa-dse.cc | 7 +++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/gcc.dg/torture/pr103987.c b/gcc/testsuite/gcc.dg/torture/pr103987.c new file mode 100644 index 00000000000..6bfc76881a1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr103987.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ + +void foo(); + +void bar(int i) +{ + foo (i); +} + +void foo(int *p) +{ + *p = 0; +} diff --git a/gcc/tree-ssa-dse.cc b/gcc/tree-ssa-dse.cc index ed73bee932a..47997df2125 100644 --- a/gcc/tree-ssa-dse.cc +++ b/gcc/tree-ssa-dse.cc @@ -43,6 +43,7 @@ along with GCC; see the file COPYING3. If not see #include "cgraph.h" #include "ipa-modref-tree.h" #include "ipa-modref.h" +#include "target.h" /* This file implements dead store elimination. @@ -1190,10 +1191,12 @@ dse_optimize_call (gimple_stmt_iterator *gsi, sbitmap live_bytes) { tree arg = access_node.get_call_arg (stmt); - if (!arg) + if (!arg || !POINTER_TYPE_P (TREE_TYPE (arg))) return false; - if (integer_zerop (arg) && flag_delete_null_pointer_checks) + if (integer_zerop (arg) + && !targetm.addr_space.zero_address_valid + (TYPE_ADDR_SPACE (TREE_TYPE (arg)))) continue; ao_ref ref;