From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id E2C773AA88E0 for ; Tue, 30 Aug 2022 08:36:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E2C773AA88E0 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id EC5B821DAC for ; Tue, 30 Aug 2022 08:36:40 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id E784A2C141 for ; Tue, 30 Aug 2022 08:36:40 +0000 (UTC) Date: Tue, 30 Aug 2022 08:36:39 +0000 (UTC) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Use reachability analysis to improve uninit diagnostic User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Aug 2022 08:36:46 -0000 Message-ID: <20220830083639.0JksGdcX5hY8SREQQzq0xcAq_fCsowh3oVKhv70mPVU@z> This patch does what the comment in uninit diagnostic suggests. When the value-numbering run done without optimizing figures there's a fallthru path, consider blocks on it as always executed. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. * tree-ssa-uninit.cc (warn_uninitialized_vars): Pre-compute the set of fallthru reachable blocks from function entry and use that to determine wlims.always_executed. --- gcc/tree-ssa-uninit.cc | 47 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/gcc/tree-ssa-uninit.cc b/gcc/tree-ssa-uninit.cc index 0bd567f237c..c25fbe6381e 100644 --- a/gcc/tree-ssa-uninit.cc +++ b/gcc/tree-ssa-uninit.cc @@ -988,10 +988,43 @@ warn_uninitialized_vars (bool wmaybe_uninit) wlimits wlims = { }; wlims.wmaybe_uninit = wmaybe_uninit; - gimple_stmt_iterator gsi; - basic_block bb; + auto_bb_flag ft_reachable (cfun); + + /* Mark blocks that are always executed when we ignore provably + not executed edges. */ + basic_block bb = single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun)); + while (!(bb->flags & ft_reachable)) + { + bb->flags |= ft_reachable; + /* Find a single executable edge. */ + edge_iterator ei; + edge e, ee = NULL; + FOR_EACH_EDGE (e, ei, bb->succs) + if (e->flags & EDGE_EXECUTABLE) + { + if (!ee) + ee = e; + else + { + ee = NULL; + break; + } + } + if (ee) + bb = ee->dest; + else + { + bb = get_immediate_dominator (CDI_POST_DOMINATORS, bb); + if (!bb || bb->index == EXIT_BLOCK) + break; + } + } + FOR_EACH_BB_FN (bb, cfun) { + wlims.always_executed = (bb->flags & ft_reachable); + bb->flags &= ~ft_reachable; + edge_iterator ei; edge e; FOR_EACH_EDGE (e, ei, bb->preds) @@ -1002,14 +1035,10 @@ warn_uninitialized_vars (bool wmaybe_uninit) if (!e) continue; - basic_block succ = single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun)); - /* ??? This could be improved when we use a greedy walk and have - some edges marked as not executable. */ - wlims.always_executed = dominated_by_p (CDI_POST_DOMINATORS, succ, bb); - if (wlims.always_executed) warn_uninit_phi_uses (bb); + gimple_stmt_iterator gsi; for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) { gimple *stmt = gsi_stmt (gsi); @@ -1030,7 +1059,7 @@ warn_uninitialized_vars (bool wmaybe_uninit) FOR_EACH_SSA_USE_OPERAND (use_p, stmt, op_iter, SSA_OP_USE) { /* BIT_INSERT_EXPR first operand should not be considered - a use for the purpose of uninit warnings. */ + a use for the purpose of uninit warnings. */ if (gassign *ass = dyn_cast (stmt)) { if (gimple_assign_rhs_code (ass) == BIT_INSERT_EXPR @@ -1041,7 +1070,7 @@ warn_uninitialized_vars (bool wmaybe_uninit) if (wlims.always_executed) warn_uninit (OPT_Wuninitialized, use, SSA_NAME_VAR (use), stmt); - else if (wmaybe_uninit) + else if (wlims.wmaybe_uninit) warn_uninit (OPT_Wmaybe_uninitialized, use, SSA_NAME_VAR (use), stmt); } -- 2.35.3