From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 65224383CCF6; Wed, 31 Aug 2022 11:04:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 65224383CCF6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661943845; bh=+O1+NqM8nzsYV1iefNxNm0sJgIwN+yyqKHAt6OJDP60=; h=From:To:Subject:Date:From; b=Q/dnRcDe1Q8A5YnF2MMCi5cwF6iRWC/am25EhY7Sd631yQRwwSoyR4Zxm2fr0G4Ap jK612ZWQT9thCdRzZRRFngyOfgeOsAYJc9PsByVYfHMYw9f1LfSc/I9MljickLM6Ua EPDTPn+TanacLoCy92nFdLnGtTppa8f5Qz2u0Gv8= 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 r13-2305] tree-optimization/65244 - include asserts in predicates for uninit X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: 0cf736575286f841f6144bd58b981c269652b82e X-Git-Newrev: 40f347881ade08fe9c0f8b527f8b54bd53aed195 Message-Id: <20220831110405.65224383CCF6@sourceware.org> Date: Wed, 31 Aug 2022 11:04:05 +0000 (GMT) List-Id: https://gcc.gnu.org/g:40f347881ade08fe9c0f8b527f8b54bd53aed195 commit r13-2305-g40f347881ade08fe9c0f8b527f8b54bd53aed195 Author: Richard Biener Date: Tue Aug 30 10:31:26 2022 +0200 tree-optimization/65244 - include asserts in predicates for uninit When uninit computes the actual predicates from the control dependence edges it currently skips those that are assert-like (where one edge leads to a block which ends in a noreturn call). That leads to bogus uninit diagnostics when applied on the USE side. PR tree-optimization/65244 * gimple-predicate-analysis.h (predicate::init_from_control_deps): Add argument to specify whether the predicate is for the USE. * gimple-predicate-analysis.cc (predicate::init_from_control_deps): Also include predicates effective fallthru control edges when the predicate is for the USE. * gcc.dg/uninit-pr65244-2.c: New testcase. Diff: --- gcc/gimple-predicate-analysis.cc | 17 +++++++++++------ gcc/gimple-predicate-analysis.h | 2 +- gcc/testsuite/gcc.dg/uninit-pr65244-2.c | 20 ++++++++++++++++++++ 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/gcc/gimple-predicate-analysis.cc b/gcc/gimple-predicate-analysis.cc index 6b2e347536a..49500b77832 100644 --- a/gcc/gimple-predicate-analysis.cc +++ b/gcc/gimple-predicate-analysis.cc @@ -1666,7 +1666,7 @@ predicate::normalize (gimple *use_or_def, bool is_use) void predicate::init_from_control_deps (const vec *dep_chains, - unsigned num_chains) + unsigned num_chains, bool is_use) { gcc_assert (is_empty ()); @@ -1675,7 +1675,8 @@ predicate::init_from_control_deps (const vec *dep_chains, return; if (DEBUG_PREDICATE_ANALYZER && dump_file) - fprintf (dump_file, "init_from_control_deps {%s}:\n", + fprintf (dump_file, "init_from_control_deps [%s] {%s}:\n", + is_use ? "USE" : "DEF", format_edge_vecs (dep_chains, num_chains).c_str ()); /* Convert the control dependency chain into a set of predicates. */ @@ -1711,8 +1712,12 @@ predicate::init_from_control_deps (const vec *dep_chains, if (is_gimple_call (cond_stmt) && EDGE_COUNT (e->src->succs) >= 2) /* Ignore EH edge. Can add assertion on the other edge's flag. */ continue; - /* Skip if there is essentially one succesor. */ - if (EDGE_COUNT (e->src->succs) == 2) + /* Skip this edge if it is bypassing an abort - when the + condition is not satisfied we are neither reaching the + definition nor the use so it isn't meaningful. Note if + we are processing the use predicate the condition is + meaningful. See PR65244. */ + if (!is_use && EDGE_COUNT (e->src->succs) == 2) { edge e1; edge_iterator ei1; @@ -1941,7 +1946,7 @@ uninit_analysis::init_use_preds (predicate &use_preds, basic_block def_bb, condition under which the definition in DEF_BB is used in USE_BB. Each OR subexpression is represented by one element of DEP_CHAINS, where each element consists of a series of AND subexpressions. */ - use_preds.init_from_control_deps (dep_chains, num_chains); + use_preds.init_from_control_deps (dep_chains, num_chains, true); return !use_preds.is_empty (); } @@ -2050,7 +2055,7 @@ uninit_analysis::init_from_phi_def (gphi *phi) /* Convert control dependence chains to the predicate in *THIS under which the PHI operands are defined to values for which M_EVAL is false. */ - m_phi_def_preds.init_from_control_deps (dep_chains, num_chains); + m_phi_def_preds.init_from_control_deps (dep_chains, num_chains, false); return !m_phi_def_preds.is_empty (); } diff --git a/gcc/gimple-predicate-analysis.h b/gcc/gimple-predicate-analysis.h index 48da8f70efd..bc0248d7a93 100644 --- a/gcc/gimple-predicate-analysis.h +++ b/gcc/gimple-predicate-analysis.h @@ -65,7 +65,7 @@ class predicate return m_preds; } - void init_from_control_deps (const vec *, unsigned); + void init_from_control_deps (const vec *, unsigned, bool); void dump (gimple *, const char *) const; diff --git a/gcc/testsuite/gcc.dg/uninit-pr65244-2.c b/gcc/testsuite/gcc.dg/uninit-pr65244-2.c new file mode 100644 index 00000000000..a28893cdcb5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-pr65244-2.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-Og -Wuninitialized -ftree-bit-ccp -fno-thread-jumps -fdump-tree-uninit2" } */ + +void exit(int __status) __attribute__ ((__noreturn__)); +int posix_memalign(void **__memptr, __SIZE_TYPE__ __alignment, + __SIZE_TYPE__ __size); + +void *f(void) +{ + void *ptr; + + if (posix_memalign(&ptr, 16, 256) != 0) + exit(1); + + return ptr; /* { dg-bogus "uninitialized" } */ +} + +/* Make sure the uninit pass has something to do, add to the set of + disabled optimizations if not. */ +/* { dg-final { scan-tree-dump "# ptr_. = PHI" "uninit2" } } */