From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id DFC3A3858D3C for ; Mon, 8 Nov 2021 16:57:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DFC3A3858D3C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id C06641FDB8 for ; Mon, 8 Nov 2021 16:57:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1636390623; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=7z39UyW0/+6L0DR2p0fM+Qi1W2f1441wxG59h6oAe0A=; b=wdsCxJPzTmdhLmy1b6tDGwiItLn9IjWujW9cDMKpfqHwh4OtPOEnApEMEkeSvqIrniTG0G R+ulpMxiVZVXtt+4j17czk/mdGaub1uzuH70V4G3oKY0BJFIM0TNbXk2dwd3zp47At1znw kkbfsgU1kXX5K0mFmgdKgfuay98iuyM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1636390623; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=7z39UyW0/+6L0DR2p0fM+Qi1W2f1441wxG59h6oAe0A=; b=6Z0uGDcrYysuSdfSxzGK9Gi7TFUw6g0aI8trYjCk2GHxoay48+n6lRhw8yvRx6Zrz9gihU AjLoJiwNLr4XfKDQ== Received: from suse.cz (unknown [10.100.200.98]) (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 A2293A3B85; Mon, 8 Nov 2021 16:57:03 +0000 (UTC) From: Martin Jambor To: GCC Patches Cc: Richard Biener Subject: [PATCH] ipa: Fix segfault when remapping debug_binds with expressions (PR 103132) User-Agent: Notmuch/0.33.2 (https://notmuchmail.org) Emacs/27.2 (x86_64-suse-linux-gnu) Date: Mon, 08 Nov 2021 17:57:00 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-11.0 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Mon, 08 Nov 2021 16:57:06 -0000 Hi, my initial implementation of the method ipa_param_body_adjustments::remap_with_debug_expressions was based on the assumption that if it was asked to remap an expression (as opposed to a simple SSA_NAME), the expression would not contain an SSA_NAME operand which is to be debug-reset. While that is true for when called from ipa_param_body_adjustments::prepare_debug_expressions, it turns out it is not true when invoked from remap_gimple_stmt in tree-inline.c. This patch adds a simple logic to handle such cases and simply map the entire value to NULL_TREE in those cases. I have bootstrapped and tested the patch on x86_64-linux. OK for trunk? Thanks, Martin gcc/ChangeLog: 2021-11-08 Martin Jambor PR ipa/103132 * ipa-param-manipulation.c (replace_with_mapped_expr): Early return with error_mark_mode when part of expression is mapped to NULL. (ipa_param_body_adjustments::remap_with_debug_expressions): Set mapped value to NULL if walk_tree returns error_mark_mode. gcc/testsuite/ChangeLog: 2021-11-08 Martin Jambor PR ipa/103132 * gcc.dg/ipa/pr103132.c: New test. --- gcc/ipa-param-manipulation.c | 27 +++++++++++++++++++-------- gcc/testsuite/gcc.dg/ipa/pr103132.c | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/ipa/pr103132.c diff --git a/gcc/ipa-param-manipulation.c b/gcc/ipa-param-manipulation.c index 44f3bed2640..4610fc4ac03 100644 --- a/gcc/ipa-param-manipulation.c +++ b/gcc/ipa-param-manipulation.c @@ -1071,8 +1071,9 @@ ipa_param_body_adjustments::mark_dead_statements (tree dead_param, } /* Callback to walk_tree. If REMAP is an SSA_NAME that is present in hash_map - passed in DATA, replace it with unshared version of what it was mapped - to. */ + passed in DATA, replace it with unshared version of what it was mapped to. + If an SSA argument would be remapped to NULL, the whole operation needs to + abort which is signaled by returning error_mark_node. */ static tree replace_with_mapped_expr (tree *remap, int *walk_subtrees, void *data) @@ -1089,7 +1090,11 @@ replace_with_mapped_expr (tree *remap, int *walk_subtrees, void *data) hash_map *equivs = (hash_map *) data; if (tree *p = equivs->get (*remap)) - *remap = unshare_expr (*p); + { + if (!*p) + return error_mark_node; + *remap = unshare_expr (*p); + } return 0; } @@ -1100,16 +1105,22 @@ void ipa_param_body_adjustments::remap_with_debug_expressions (tree *t) { /* If *t is an SSA_NAME which should have its debug statements reset, it is - mapped to NULL in the hash_map. We need to handle that case separately or - otherwise the walker would segfault. No expression that is more - complicated than that can have its operands mapped to NULL. */ + mapped to NULL in the hash_map. + + It is perhaps simpler to handle the SSA_NAME cases directly and only + invoke walk_tree on more complex expressions. When + remap_with_debug_expressions is called from tree-inline.c, a to-be-reset + SSA_NAME can be an operand to such expressions and the entire debug + variable we are remapping should be reset. This is signaled by walk_tree + returning error_mark_node and done by setting *t to NULL. */ if (TREE_CODE (*t) == SSA_NAME) { if (tree *p = m_dead_ssa_debug_equiv.get (*t)) *t = *p; } - else - walk_tree (t, replace_with_mapped_expr, &m_dead_ssa_debug_equiv, NULL); + else if (walk_tree (t, replace_with_mapped_expr, + &m_dead_ssa_debug_equiv, NULL) == error_mark_node) + *t = NULL_TREE; } /* For an SSA_NAME DEAD_SSA which is about to be DCEd because it is based on a diff --git a/gcc/testsuite/gcc.dg/ipa/pr103132.c b/gcc/testsuite/gcc.dg/ipa/pr103132.c new file mode 100644 index 00000000000..bef56494c03 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/pr103132.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -g" } */ + +int globus_i_GLOBUS_GRIDFTP_SERVER_debug_handle_1; +int globus_l_gfs_ipc_unpack_data__sz; +void globus_i_GLOBUS_GRIDFTP_SERVER_debug_printf(const char *, ...); +static void globus_l_gfs_ipc_unpack_cred(int len) { + if (globus_i_GLOBUS_GRIDFTP_SERVER_debug_handle_1) + globus_i_GLOBUS_GRIDFTP_SERVER_debug_printf("", __func__); +} +static void globus_l_gfs_ipc_unpack_data(int len) { + for (; globus_l_gfs_ipc_unpack_data__sz;) + len--; + len -= 4; + len -= 4; + globus_l_gfs_ipc_unpack_cred(len); +} +void globus_l_gfs_ipc_reply_read_body_cb(int len) +{ globus_l_gfs_ipc_unpack_data(len); } -- 2.33.0