From patchwork Mon Dec 5 15:39:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 61478 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7482F392AC06 for ; Mon, 5 Dec 2022 15:40:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7482F392AC06 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670254825; bh=G1Fs2TDVyJKb29YyIhPT9/wzGJ2R757HoE3bI+zyidk=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=j9UyTGg1D75Es1nVRe5sqYNbDlDOL4zXuheecYdjjpiodSdT62DH9arUbK+kGMyGI 8M3KIK6HV5ymEGlDJlzAnhc5c8GvknSrKkzgMVYfGqUCF/k7NSZydU1cYVFj1ubpRf aT7TsBJQ0jtGkVLpAn58h3UtpwvDfo+Cryp+MLmI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 9CBD038AA271 for ; Mon, 5 Dec 2022 15:39:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9CBD038AA271 Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 736321FE4D for ; Mon, 5 Dec 2022 15:39:55 +0000 (UTC) Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap1.suse-dmz.suse.de (Postfix) with ESMTPS id 5F6A813326 for ; Mon, 5 Dec 2022 15:39:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id 7bIUFssQjmMcOwAAGKfGzw (envelope-from ) for ; Mon, 05 Dec 2022 15:39:55 +0000 Date: Mon, 5 Dec 2022 16:39:55 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end/40635 - SSA update losing PHI arg loations MIME-Version: 1.0 Message-Id: <20221205153955.5F6A813326@imap1.suse-dmz.suse.de> X-Spam-Status: No, score=-11.8 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 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-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The following fixes an issue where SSA update loses PHI argument locations when updating PHI nodes it didn't create as part of the SSA update. For the case where the reaching def is the same as the current argument opt to do nothing and for the case where the PHI argument already has a location keep that (that's an indication the PHI node wasn't created as part of the update SSA process). Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. PR middle-end/40635 * tree-into-ssa.cc (rewrite_update_phi_arguments): Only update the argument when the reaching definition is different from the current argument. Keep an existing argument location. * gcc.dg/uninit-pr40635.c: New testcase. --- gcc/testsuite/gcc.dg/uninit-pr40635.c | 33 +++++++++++++++++++++++++++ gcc/tree-into-ssa.cc | 11 +++++---- 2 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/uninit-pr40635.c diff --git a/gcc/testsuite/gcc.dg/uninit-pr40635.c b/gcc/testsuite/gcc.dg/uninit-pr40635.c new file mode 100644 index 00000000000..fab7c3d49d9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-pr40635.c @@ -0,0 +1,33 @@ +/* { dg-do compile } */ +/* { dg-options "-O -Wuninitialized" } */ + +struct hostent { + char **h_addr_list; +}; +struct hostent *gethostbyname(const char*); +int socket(void); +int close(int); +int connect(int, const char*); + +int get_tcp_socket(const char *machine) +{ + struct hostent *hp; + int s42, x; + char **addr; + + hp = gethostbyname(machine); + x = 0; + for (addr = hp->h_addr_list; *addr; addr++) + { + s42 = socket(); + if (s42 < 0) + return -1; + x = connect(s42, *addr); + if (x == 0) + break; + close(s42); + } + if (x < 0) + return -1; + return s42; /* { dg-warning "uninitialized" } */ +} diff --git a/gcc/tree-into-ssa.cc b/gcc/tree-into-ssa.cc index f21ed2bea3f..9a2417d2b0b 100644 --- a/gcc/tree-into-ssa.cc +++ b/gcc/tree-into-ssa.cc @@ -2110,7 +2110,6 @@ rewrite_update_phi_arguments (basic_block bb) symbol we may find NULL arguments. That's why we take the symbol from the LHS of the PHI node. */ reaching_def = get_reaching_def (lhs_sym); - } else { @@ -2122,8 +2121,9 @@ rewrite_update_phi_arguments (basic_block bb) reaching_def = get_reaching_def (arg); } - /* Update the argument if there is a reaching def. */ - if (reaching_def) + /* Update the argument if there is a reaching def different + from arg. */ + if (reaching_def && reaching_def != arg) { location_t locus; int arg_i = PHI_ARG_INDEX_FROM_USE (arg_p); @@ -2133,6 +2133,10 @@ rewrite_update_phi_arguments (basic_block bb) /* Virtual operands do not need a location. */ if (virtual_operand_p (reaching_def)) locus = UNKNOWN_LOCATION; + /* If SSA update didn't insert this PHI the argument + might have a location already, keep that. */ + else if (gimple_phi_arg_has_location (phi, arg_i)) + locus = gimple_phi_arg_location (phi, arg_i); else { gimple *stmt = SSA_NAME_DEF_STMT (reaching_def); @@ -2150,7 +2154,6 @@ rewrite_update_phi_arguments (basic_block bb) gimple_phi_arg_set_location (phi, arg_i, locus); } - if (e->flags & EDGE_ABNORMAL) SSA_NAME_OCCURS_IN_ABNORMAL_PHI (USE_FROM_PTR (arg_p)) = 1; }