From patchwork Tue Oct 31 21:28:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 832731 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-465653-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="AKFmQSif"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yRPcL5rDlz9t3x for ; Wed, 1 Nov 2017 08:29:01 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=MZnMgPwVIXu4vkFJQDW4wM5D2GdVEWpBIrFlFZ2v8zLWfHpQsbLKR ManaLRpn09HfcPah6ZZy+3gZ/Kv/6EBbEO80/5YkoHQ7MldNx8OCRr7BFF6aQmHQ 06dqFjU6CbM/bdNdQKYfhRnWKOWT+UfgpiaI3TJGNor5bGHrrU+XOk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=Wh+KthUXaKEMlTVdstabZufWj8U=; b=AKFmQSifSQoho8ea3Fic wFw9/iHvZn6XfcVUVNo8T8ektrPZ7YxqzZ7nh+s1Usy5T1hxa6mxcNr8aNzuKfHk ayPOqIG+TqpO++UP+t874s2OB7qQkqd9inuD0AV2gGIplZggPR4jvLPZmkmpvgfM A+uucQDmUTmN+Z2HgRnkJw4= Received: (qmail 73746 invoked by alias); 31 Oct 2017 21:28:54 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 73734 invoked by uid 89); 31 Oct 2017 21:28:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy=2142, tomorrow, Item, policy X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 31 Oct 2017 21:28:52 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 346FFADD2 for ; Tue, 31 Oct 2017 21:28:50 +0000 (UTC) Date: Tue, 31 Oct 2017 22:28:49 +0100 From: Martin Jambor To: GCC Patches Subject: [PR 81702] Remove devirtualization assert Message-ID: <20171031212849.3vjeohovvckqzti7@virgil.suse.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170912 (1.9.0) X-IsSubscribed: yes Hi, in PR 81702, both me and Honza came to the conclusion that the assert that is being hit can be removed if it is indeed OK that a particular variable is constructed without a DECL_INITIAL. Yesterday Nathan confirmed that in this case it is fine. So the patch below removes the assert. Bootstrapped and tested on x86_64-linux, I will commit it to teunk as pre-approved in Bugzilla in a few moments. I will commit it tomorrow to the gcc-7-branch after testing it there too. Thanks, Martin 2017-10-31 Martin Jambor PR c++/81702 * gimple-fold.c (gimple_get_virt_method_for_vtable): Remove assert. testsuite/ * g++.dg/tree-ssa/pr81702.C: New test. --- gcc/gimple-fold.c | 1 - gcc/testsuite/g++.dg/tree-ssa/pr81702.C | 110 ++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/tree-ssa/pr81702.C diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index cb33c1e09fe..85fd3971946 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -6586,7 +6586,6 @@ gimple_get_virt_method_for_vtable (HOST_WIDE_INT token, gcc_assert (init); if (init == error_mark_node) { - gcc_assert (in_lto_p); /* Pass down that we lost track of the target. */ if (can_refer) *can_refer = false; diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr81702.C b/gcc/testsuite/g++.dg/tree-ssa/pr81702.C new file mode 100644 index 00000000000..85acd857e67 --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/pr81702.C @@ -0,0 +1,110 @@ +// { dg-do compile } +// { dg-options "-O2" } + +namespace std { + struct type_info + { + virtual bool __do_catch(const type_info *__thr_type, void **__thr_obj, + unsigned __outer) const; + }; +} + +template< typename VALUE_T, typename TYPE > +struct List_policy +{ + typedef VALUE_T *Value_type; + typedef TYPE **Type; + typedef TYPE *Head_type; + typedef TYPE Item_type; +}; + +template< typename POLICY > +class List +{ +public: + typedef typename POLICY::Value_type Value_type; + class Iterator + { + typedef typename POLICY::Type Internal_type; + public: + typedef typename POLICY::Value_type value_type; + typedef typename POLICY::Value_type Value_type; + Value_type operator -> () const { return static_cast(*_c); } + Internal_type _c; + }; + Iterator begin() { return Iterator(); } + Iterator end() { return Iterator(); } + typename POLICY::Head_type _f; +}; + +template class H_list_item_t { }; + +template< typename T, typename POLICY > +class H_list : public List +{ +public: + typedef typename POLICY::Item_type Item; + typedef List Base; + typedef typename Base::Iterator Iterator; + Iterator insert(T *e, Iterator const &pred) + { + Item **x = &this->_f; + *x = static_cast(e); + return Iterator(); + } +}; + +template< typename T > +struct H_list_t : H_list > > +{ + H_list_t(bool b) : H_list > >(b) {} +}; + +template< typename BASE, typename MATCH_RESULT > +struct Type_matcher : H_list_item_t +{ + explicit Type_matcher(std::type_info const *type); + typedef MATCH_RESULT Match_result; + +private: + std::type_info *_type; + typedef H_list_t List; + typedef typename List::Iterator Iterator; + static List _for_type; +}; + +template< typename BASE, typename MR > +Type_matcher::Type_matcher(std::type_info const *t) +{ + Iterator c = _for_type.begin(); + t->__do_catch(c->_type, 0, 0); + _for_type.insert(static_cast(this), _for_type.begin()); +} + +template< typename VI, typename HW > +class Fa : public Type_matcher, VI*> +{ +public: + typedef Fa Self; + virtual VI *do_match(HW *f) = 0; + explicit Fa(std::type_info const *type) : Type_matcher(type) {} +}; + +class Res {}; +typedef Fa R_fac; + +template< typename VI, typename HW_BASE, typename HW, typename BASE > +class Fa_t : public BASE +{ +public: + Fa_t() : BASE(&typeid(HW)) {} + VI *do_match(HW_BASE *) { return 0; } +}; + +template< typename VI, typename HW > +class Resource_factory_t : public Fa_t {}; + +class Foo {}; +class Foo2; +class Foo3 : public Res {}; +Resource_factory_t _x;