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 517BE3858D1E for ; Wed, 13 Jul 2022 21:05:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 517BE3858D1E 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 067C234401 for ; Wed, 13 Jul 2022 21:05:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1657746338; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=jXDzfiR1Ml+PCi0zhSd2yR5r9Sc7G0+980qMMFnKwas=; b=ITzk4KILzMPiKFlcSNbLTtsyNz+qSPKGHvpUQu6xEW2pl3gdLVBzIq0oBuV8mN8IgJFq4q uB4WJJ7J4SaFC7qbUIuBJ9dSMnJx9AT1HwY2Fm1E92dnlJWw8gUfiqsDwlPvDCbs9HXFF6 FR29b6BO5oilRbtBaWAMICtQnYAOru4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1657746338; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=jXDzfiR1Ml+PCi0zhSd2yR5r9Sc7G0+980qMMFnKwas=; b=efFf3pktzE11u0f5406f+PhxFfbyO06TzFpsGDcFsWrvcKWDscuTc/6QilS6pD4KvGw4V5 ZXGWiOxVCAmFkADg== 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 D72A32C141; Wed, 13 Jul 2022 21:05:37 +0000 (UTC) From: Martin Jambor To: GCC Patches Cc: Jan Hubicka Subject: [PATCH] ipa-cp: Fix assert triggering with -fno-toplevel-reorder (PR 106260) User-Agent: Notmuch/0.35 (https://notmuchmail.org) Emacs/28.1 (x86_64-suse-linux-gnu) Date: Wed, 13 Jul 2022 23:05:34 +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: Wed, 13 Jul 2022 21:05:40 -0000 Hi, with -fno-toplevel-reorder (and -fwhole-program), there apparently can be local functions without any callers. This is something that IPA-CP does not like because its propagation verifier checks that local functions do not end up with TOP in their lattices. Therefore there is an assert checking that all call-less unreachable functions have been removed, which triggers in PR 106260 with these two options. This patch detects the situation and marks the lattices as variable, thus avoiding both the assert trigger and the verification failure. Bootstrapped and tested on x86_64-linux. OK for master and then all active release branches? Thanks, Martin gcc/ChangeLog: 2022-07-13 Martin Jambor PR ipa/106260 * ipa-cp.cc (initialize_node_lattices): Replace assert that there are callers with handling that situation when -fno-toplevel_reorder. gcc/testsuite/ChangeLog: 2022-07-13 Martin Jambor PR ipa/106260 * g++.dg/ipa/pr106260.C: New test. --- gcc/ipa-cp.cc | 6 ++- gcc/testsuite/g++.dg/ipa/pr106260.C | 64 +++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/ipa/pr106260.C diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc index 543a9334e2c..f699a8dadc0 100644 --- a/gcc/ipa-cp.cc +++ b/gcc/ipa-cp.cc @@ -1286,10 +1286,14 @@ initialize_node_lattices (struct cgraph_node *node) int caller_count = 0; node->call_for_symbol_thunks_and_aliases (count_callers, &caller_count, true); - gcc_checking_assert (caller_count > 0); if (caller_count == 1) node->call_for_symbol_thunks_and_aliases (set_single_call_flag, NULL, true); + else if (caller_count == 0) + { + gcc_checking_assert (!opt_for_fn (node->decl, flag_toplevel_reorder)); + variable = true; + } } else { diff --git a/gcc/testsuite/g++.dg/ipa/pr106260.C b/gcc/testsuite/g++.dg/ipa/pr106260.C new file mode 100644 index 00000000000..bd3b6e0af79 --- /dev/null +++ b/gcc/testsuite/g++.dg/ipa/pr106260.C @@ -0,0 +1,64 @@ +// { dg-do compile } +// { dg-options "-O2 -std=gnu++14 -fwhole-program -fno-unit-at-a-time" } + +struct A; +template +struct Q { Q (T); }; +template +struct U { + ~U () { m1 (nullptr); } + D m2 (); + T *u; + void m1 (T *) { m2 () (u); } +}; +struct F { F (int *); }; +template +using W = Q; +int a, b; +void fn1 (void *); +template +void +fn2 (T *x) +{ + if (x) + x->~T(); + fn1 (x); +} +template +struct C { + void operator() (T *x) { fn2 (x); } +}; +struct D; +template > +using V = U; +struct A { + A (int *); +}; +struct S; +struct G { + V m3 (); +}; +struct S { + int e; + virtual ~S () {} +}; +template +struct H { + H (int, T x, int) : h(x) {} + G g; + void m4 () { g.m3 (); } + T h; +}; +struct I { + I(A, W); +}; +void +test () +{ + A c (&b); + W d (&b); + I e (c, d); + H f (0, e, a); + f.m4 (); +} + -- 2.36.1