From patchwork Fri Dec 8 10:31:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1873763 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=r73tVdN7; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=ahc6/BAf; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SmnVj5HxDz23mf for ; Fri, 8 Dec 2023 21:31:24 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C74FC385AC09 for ; Fri, 8 Dec 2023 10:31:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id F2B3A3858CDB for ; Fri, 8 Dec 2023 10:31:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F2B3A3858CDB Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F2B3A3858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702031472; cv=none; b=nIAB2bMWVHSheelZyA+llRYVmJ30WPYYmeVziz1oc5vs/nN9KBHGUtGHNBpPB84+mQPSWvxt6XtWsSKFw+WyF48T2l8P57UOJb3LarQEAMUgDvZx9O6cvQfv/AWYwMS9RHGJglXCtm3MNKS/dhnrN4eiOzRDENvFLJN1C0O+vuA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702031472; c=relaxed/simple; bh=wceLE8cTphhjE+jc7sy4IOwcfhpbFbkGFioUtb3hDV4=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:MIME-Version: Message-Id; b=PaiUmRqR9i9QvmhAa3eWWEeHMDObeMElSxmjpvlVIcJUKAKWQpMww6TC3mhvTrm+8bAwDEnre8AmDNlFos69dj5AixYwrn0Kdq8k9JeNy0SB5tRSR7tCgzCWvxICLPL94Ma4vGdCMOqIEm4h4mYoLF7EIeKntYPZhmbOsrpgfeA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D7FFE2211A for ; Fri, 8 Dec 2023 10:31:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702031469; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=SKYl6QEPD2Jo22CSZDjCgatxnBiDlkgrxuVgaZtgmsQ=; b=r73tVdN73BaTRUUp5LqY2rgKmuXVYBWStm92lCHrytbPi6UITHmQebFlzOXU1SeDtR4ON4 oLuf7IQU0NbNy+Y4o8q/NDTDqlRbdsrfm3cvR2QAF7jYMNsJxiVAQG5u9hiJNDM3IsWVo+ 9NTl0QQOKJtp9BiEfrDcrBU88izeMug= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702031469; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=SKYl6QEPD2Jo22CSZDjCgatxnBiDlkgrxuVgaZtgmsQ=; b=ahc6/BAf6uft9Dm86HDOubRtJCvHaGrWUI/I33m9oCjVlC+Tgoi/oOiXi+LW7zFDFJnvgC VK8ofxH6EOvbE3Cw== Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id A8303138FF for ; Fri, 8 Dec 2023 10:31:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id n2lkJm3wcmV6UAAAn2gu4w (envelope-from ) for ; Fri, 08 Dec 2023 10:31:09 +0000 Date: Fri, 8 Dec 2023 11:31:09 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/112909 - uninit diagnostic with abnormal copy MIME-Version: 1.0 Message-Id: <20231208103109.A8303138FF@imap2.dmz-prg2.suse.org> X-Spamd-Result: default: False [3.79 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[gcc-patches@gcc.gnu.org]; TO_DN_NONE(0.00)[]; R_SPF_SOFTFAIL(4.60)[~all:c]; RCPT_COUNT_ONE(0.00)[1]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MX_GOOD(-0.01)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(2.20)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%]; DMARC_POLICY_SOFTFAIL(0.10)[suse.de : No valid SPF, No valid DKIM,none] X-Spamd-Bar: +++ X-Rspamd-Server: rspamd1 X-Rspamd-Queue-Id: D7FFE2211A X-Spam-Score: 3.79 Authentication-Results: smtp-out1.suse.de; dkim=none; spf=softfail (smtp-out1.suse.de: 2a07:de40:b281:104:10:150:64:98 is neither permitted nor denied by domain of rguenther@suse.de) smtp.mailfrom=rguenther@suse.de; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=suse.de (policy=none) X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org The following avoids spurious uninit diagnostics for SSA name copies which mostly appear when the source is marked as abnormal which prevents copy propagation. To prevent regressions I remove the bail out for anonymous SSA names in the PHI arg place from warn_uninitialized_phi leaving that to warn_uninit where I handle SSA copies from a SSA name which isn't anonymous. In theory this might cause more valid and false positive diagnostics to pop up. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/112909 * tree-ssa-uninit.cc (find_uninit_use): Look through a single level of SSA name copies with single use. * gcc.dg/uninit-pr112909.c: New testcase. --- gcc/testsuite/gcc.dg/uninit-pr112909.c | 28 +++++++++++++++ gcc/tree-ssa-uninit.cc | 47 ++++++++++++++++++++------ 2 files changed, 64 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/uninit-pr112909.c diff --git a/gcc/testsuite/gcc.dg/uninit-pr112909.c b/gcc/testsuite/gcc.dg/uninit-pr112909.c new file mode 100644 index 00000000000..d2998f715aa --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-pr112909.c @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wuninitialized" } */ + +struct machine_thread_all_state { + int set; +} _hurd_setup_sighandler_state; +int _hurd_setup_sighandler_ss_0; +struct { + int ctx; +} *_hurd_setup_sighandler_stackframe; +void _setjmp(); +void __thread_get_state(); +int machine_get_basic_state(struct machine_thread_all_state *state) { + if (state->set) + __thread_get_state(); + return 1; +} +int *_hurd_setup_sighandler() { + int *scp; /* { dg-bogus "used uninitialized" } */ + if (_hurd_setup_sighandler_ss_0) { + _setjmp(); + _hurd_setup_sighandler_state.set |= 5; + } + machine_get_basic_state(&_hurd_setup_sighandler_state); + scp = &_hurd_setup_sighandler_stackframe->ctx; + _setjmp(); + return scp; +} diff --git a/gcc/tree-ssa-uninit.cc b/gcc/tree-ssa-uninit.cc index f42f76cd5c6..9a7c7d12dd8 100644 --- a/gcc/tree-ssa-uninit.cc +++ b/gcc/tree-ssa-uninit.cc @@ -204,14 +204,29 @@ warn_uninit (opt_code opt, tree t, tree var, gimple *context, { var_def_stmt = SSA_NAME_DEF_STMT (t); - if (is_gimple_assign (var_def_stmt) - && gimple_assign_rhs_code (var_def_stmt) == COMPLEX_EXPR) + if (gassign *ass = dyn_cast (var_def_stmt)) { - tree v = gimple_assign_rhs1 (var_def_stmt); - if (TREE_CODE (v) == SSA_NAME - && has_undefined_value_p (v) - && zerop (gimple_assign_rhs2 (var_def_stmt))) - var = SSA_NAME_VAR (v); + switch (gimple_assign_rhs_code (var_def_stmt)) + { + case COMPLEX_EXPR: + { + tree v = gimple_assign_rhs1 (ass); + if (TREE_CODE (v) == SSA_NAME + && has_undefined_value_p (v) + && zerop (gimple_assign_rhs2 (ass))) + var = SSA_NAME_VAR (v); + break; + } + case SSA_NAME: + { + tree v = gimple_assign_rhs1 (ass); + if (TREE_CODE (v) == SSA_NAME + && SSA_NAME_VAR (v)) + var = SSA_NAME_VAR (v); + break; + } + default:; + } } if (gimple_call_internal_p (var_def_stmt, IFN_DEFERRED_INIT)) @@ -1229,6 +1244,18 @@ find_uninit_use (gphi *phi, unsigned uninit_opnds, int *bb_to_rpo) if (is_gimple_debug (use_stmt)) continue; + /* Look through a single level of SSA name copies. This is + important for copies involving abnormals which we can't always + proapgate out but which result in spurious unguarded uses. */ + use_operand_p use2_p; + gimple *use2_stmt; + if (gimple_assign_ssa_name_copy_p (use_stmt) + && single_imm_use (gimple_assign_lhs (use_stmt), &use2_p, &use2_stmt)) + { + use_p = use2_p; + use_stmt = use2_stmt; + } + if (gphi *use_phi = dyn_cast (use_stmt)) { unsigned idx = PHI_ARG_INDEX_FROM_USE (use_p); @@ -1262,9 +1289,9 @@ find_uninit_use (gphi *phi, unsigned uninit_opnds, int *bb_to_rpo) e->src->index, e->dest->index); print_gimple_stmt (dump_file, use_stmt, 0); } - /* Found a phi use that is not guarded, mark the phi_result as + /* Found a phi use that is not guarded, mark the use as possibly undefined. */ - possibly_undefined_names->add (phi_result); + possibly_undefined_names->add (USE_FROM_PTR (use_p)); } else cands.safe_push (use_stmt); @@ -1318,8 +1345,6 @@ warn_uninitialized_phi (gphi *phi, unsigned uninit_opnds, int *bb_to_rpo) unsigned phiarg_index = MASK_FIRST_SET_BIT (uninit_opnds); tree uninit_op = gimple_phi_arg_def (phi, phiarg_index); - if (SSA_NAME_VAR (uninit_op) == NULL_TREE) - return; location_t loc = UNKNOWN_LOCATION; if (gimple_phi_arg_has_location (phi, phiarg_index))