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 5A2E53857C4A for ; Thu, 26 May 2022 14:47:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5A2E53857C4A 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-out1.suse.de (Postfix) with ESMTP id B7848218FE for ; Thu, 26 May 2022 14:47:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1653576445; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=N2FMQwFTdKddwvBhE1Zq7lTBj8WQmueKKH8+9/iZWDw=; b=PxBu3xDbsQv7SWiehN9e0+Umi13IRiY90O1Btdd38Up9bUaQ0iXF9h8Tp68dZxLqmS1Gpx t03K3Ug7yde6RSJVMkyT5RihNowxpjT8QB2cbNUBhRlqeNU8csV6CS0TkwZKgmzydVpTDa 6gu72SQqNkdbfEKFACwx8gLFwRaunZo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1653576445; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=N2FMQwFTdKddwvBhE1Zq7lTBj8WQmueKKH8+9/iZWDw=; b=Y005IV7b5LDqrGCAKjFW4ZfZcCyFGkWUCH2cU6Ij8oNt4DrImqhb0RF5QI8PkKXRGswh+q olvPp2eot8KIi5Dw== Received: from suse.cz (virgil.suse.cz [10.100.13.50]) (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 9F0392C141; Thu, 26 May 2022 14:47:25 +0000 (UTC) From: Martin Jambor To: GCC Patches Cc: Jan Hubicka , Martin Liska Subject: [PATCH] ipa: Check cst type when propagating controled uses info (PR 105639) User-Agent: Notmuch/0.35 (https://notmuchmail.org) Emacs/28.1 (x86_64-suse-linux-gnu) Date: Thu, 26 May 2022 16:47:25 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-10.9 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 May 2022 14:47:28 -0000 Hi, PR 105639 shows that code with type-mismatches can trigger an assert after runnning into a branch that was inteded only for references to variables - as opposed to references to functions. Fixed by moving the condition from the assert to the guarding if statement. Bootstrapped and tested on x86_64. OK for trunk and then gcc 12? Thanks, Martin gcc/ChangeLog: 2022-05-25 Martin Jambor PR ipa/105639 * ipa-prop.cc (propagate_controlled_uses): Check type of the constant before adding a LOAD reference. gcc/testsuite/ChangeLog: 2022-05-25 Martin Jambor PR ipa/105639 * gcc.dg/ipa/pr105639.c: New test. --- gcc/ipa-prop.cc | 10 ++++------ gcc/testsuite/gcc.dg/ipa/pr105639.c | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/ipa/pr105639.c diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc index c6c745f84a0..afd9222b5a2 100644 --- a/gcc/ipa-prop.cc +++ b/gcc/ipa-prop.cc @@ -4187,14 +4187,13 @@ propagate_controlled_uses (struct cgraph_edge *cs) { int d = ipa_get_controlled_uses (old_root_info, i); int c = rdesc->refcount; + tree cst = ipa_get_jf_constant (jf); rdesc->refcount = combine_controlled_uses_counters (c, d); if (rdesc->refcount != IPA_UNDESCRIBED_USE - && ipa_get_param_load_dereferenced (old_root_info, i)) + && ipa_get_param_load_dereferenced (old_root_info, i) + && TREE_CODE (cst) == ADDR_EXPR + && TREE_CODE (TREE_OPERAND (cst, 0)) == VAR_DECL) { - tree cst = ipa_get_jf_constant (jf); - gcc_checking_assert (TREE_CODE (cst) == ADDR_EXPR - && (TREE_CODE (TREE_OPERAND (cst, 0)) - == VAR_DECL)); symtab_node *n = symtab_node::get (TREE_OPERAND (cst, 0)); new_root->create_reference (n, IPA_REF_LOAD, NULL); if (dump_file) @@ -4204,7 +4203,6 @@ propagate_controlled_uses (struct cgraph_edge *cs) } if (rdesc->refcount == 0) { - tree cst = ipa_get_jf_constant (jf); gcc_checking_assert (TREE_CODE (cst) == ADDR_EXPR && ((TREE_CODE (TREE_OPERAND (cst, 0)) == FUNCTION_DECL) diff --git a/gcc/testsuite/gcc.dg/ipa/pr105639.c b/gcc/testsuite/gcc.dg/ipa/pr105639.c new file mode 100644 index 00000000000..5534fe93fbf --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/pr105639.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O -w" } */ + +void typedef (*cb) (void); + +static void +bar (cb *fp) +{ + (*fp) (); +} + +void +foo (void) +{ + bar (foo); +} -- 2.36.0