From patchwork Wed Nov 27 14:19:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 1201657 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-514709-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="rigCDb6D"; 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 47NNFW0h6yz9sTH for ; Thu, 28 Nov 2019 01:19:41 +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:from :subject:to:cc:message-id:date:mime-version:content-type; q=dns; s=default; b=JDy+NtwAaqjIGX6bGRygS7gOq9t3DOw7USFbem2Nx73cNR5Tp0 0DGqR00oYrxlcpY+Y6cXuX7p3sslMUaK3LMRnZTAWWEcKdLW0tfyI8qb/5xr6vSa UpmoESFzTkctsHKUY31dJdEvJ1c0tDB8kTumtqj+fXnj1zSJoRk6QHKSo= 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:from :subject:to:cc:message-id:date:mime-version:content-type; s= default; bh=F2ptttFGoQy/LkgcPTNCWuwFjdM=; b=rigCDb6DTVfOYmXdyutL jS8lnzM/nzF49sb22lkLr6O+ckIWjuy8KbdzFt//9zqBMEfL73T+g0aqPiqVqF3J jrqc2akRHw14BxylgGKFlhysnHT7uaEqPd6/hVQNLWuqtQdGDarHJFNBUKOTNuqO uH2I5rVdbtav8+2QvRM9FQc= Received: (qmail 124584 invoked by alias); 27 Nov 2019 14:19:33 -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 124559 invoked by uid 89); 27 Nov 2019 14:19:32 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 27 Nov 2019 14:19:30 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 0B90CAB7F; Wed, 27 Nov 2019 14:19:27 +0000 (UTC) From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: [PATCH] Properly use TYPE_MAIN_VARIANT in warn_types_mismatch. To: gcc-patches@gcc.gnu.org Cc: Jan Hubicka Message-ID: <00203ffd-b43a-231f-0aaf-200c377d63ad@suse.cz> Date: Wed, 27 Nov 2019 15:19:27 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 X-IsSubscribed: yes Hi. The patch is attempt to fix ICE which I see in ODR violation warning. I think the proper fix is to use TYPE_MAIN_VARIANT(t1) instead of t1 in the problematic condition. Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin gcc/ChangeLog: 2019-11-27 Martin Liska PR lto/92609 * ipa-devirt.c (warn_types_mismatch): Use TYPE_MAIN_VARIANT consistently. gcc/testsuite/ChangeLog: 2019-11-27 Martin Liska PR lto/92609 * g++.dg/lto/pr92609_0.C: New test. * g++.dg/lto/pr92609_1.C: New test. --- gcc/ipa-devirt.c | 25 ++++---- gcc/testsuite/g++.dg/lto/pr92609_0.C | 88 ++++++++++++++++++++++++++++ gcc/testsuite/g++.dg/lto/pr92609_1.C | 58 ++++++++++++++++++ 3 files changed, 159 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/g++.dg/lto/pr92609_0.C create mode 100644 gcc/testsuite/g++.dg/lto/pr92609_1.C diff --git a/gcc/ipa-devirt.c b/gcc/ipa-devirt.c index c158d3c968d..0b2475ca292 100644 --- a/gcc/ipa-devirt.c +++ b/gcc/ipa-devirt.c @@ -986,21 +986,24 @@ warn_types_mismatch (tree t1, tree t2, location_t loc1, location_t loc2) /* It is a quite common bug to reference anonymous namespace type in non-anonymous namespace class. */ - if ((type_with_linkage_p (TYPE_MAIN_VARIANT (t1)) - && type_in_anonymous_namespace_p (TYPE_MAIN_VARIANT (t1))) - || (type_with_linkage_p (TYPE_MAIN_VARIANT (t2)) - && type_in_anonymous_namespace_p (TYPE_MAIN_VARIANT (t2)))) + tree mt1 = TYPE_MAIN_VARIANT (t1); + tree mt2 = TYPE_MAIN_VARIANT (t2); + if ((type_with_linkage_p (mt1) + && type_in_anonymous_namespace_p (mt1)) + || (type_with_linkage_p (mt2) + && type_in_anonymous_namespace_p (mt2))) { - if (!type_with_linkage_p (TYPE_MAIN_VARIANT (t1)) - || !type_in_anonymous_namespace_p (TYPE_MAIN_VARIANT (t1))) + if (!type_with_linkage_p (mt1) + || !type_in_anonymous_namespace_p (mt1)) { std::swap (t1, t2); + std::swap (mt1, mt2); std::swap (loc_t1, loc_t2); } - gcc_assert (TYPE_NAME (t1) - && TREE_CODE (TYPE_NAME (t1)) == TYPE_DECL); - tree n1 = TYPE_NAME (t1); - tree n2 = TYPE_NAME (t2) ? TYPE_NAME (t2) : NULL; + gcc_assert (TYPE_NAME (mt1) + && TREE_CODE (TYPE_NAME (mt1)) == TYPE_DECL); + tree n1 = TYPE_NAME (mt1); + tree n2 = TYPE_NAME (mt2) ? TYPE_NAME (mt2) : NULL; if (TREE_CODE (n1) == TYPE_DECL) n1 = DECL_NAME (n1); @@ -1023,8 +1026,6 @@ warn_types_mismatch (tree t1, tree t2, location_t loc1, location_t loc2) "the incompatible type defined in another translation unit"); return; } - tree mt1 = TYPE_MAIN_VARIANT (t1); - tree mt2 = TYPE_MAIN_VARIANT (t2); /* If types have mangled ODR names and they are different, it is most informative to output those. This also covers types defined in different namespaces. */ diff --git a/gcc/testsuite/g++.dg/lto/pr92609_0.C b/gcc/testsuite/g++.dg/lto/pr92609_0.C new file mode 100644 index 00000000000..3cce1811d1e --- /dev/null +++ b/gcc/testsuite/g++.dg/lto/pr92609_0.C @@ -0,0 +1,88 @@ +// PR lto/92609 +// { dg-lto-do link } +// { dg-lto-options { { -fPIC -flto } } } +// { dg-require-effective-target shared } +// { dg-require-effective-target fpic } +// { dg-extra-ld-options "-shared" } + +namespace std { +inline namespace __cxx11 {} +template < typename _Default > struct __detector { using type = _Default; }; +template < typename _Default, template < typename > class > +using __detected_or = __detector< _Default >; +template < typename _Default, template < typename > class _Op > +using __detected_or_t = typename __detected_or< _Default, _Op >::type; +template < typename > class allocator; +template < class > struct char_traits; +namespace __cxx11 { +template < typename _CharT, typename = char_traits< _CharT >, + typename = allocator< _CharT > > +class basic_string; +} +struct __allocator_traits_base { + template < typename _Tp > using __pointer = typename _Tp::pointer; +}; +struct allocator_traits : __allocator_traits_base { + using pointer = __detected_or_t< char *, __pointer >; +}; +} // std +struct rebind { + typedef std::allocator_traits other; +}; +namespace std { +namespace __cxx11 { +template < typename, typename, typename > class basic_string { + struct _Alloc_hider { + rebind::other::pointer _M_p; + } _M_dataplus; + unsigned long _M_string_length; + enum { _S_local_capacity = 15 }; + union { + char _M_local_buf[_S_local_capacity + 1]; + unsigned long _M_allocated_capacity; + }; +}; +} // __cxx11 +template < typename _Tp > class __uniq_ptr_impl { + template < typename _Up > struct _Ptr { using type = _Up *; }; + +public: + using pointer = typename _Ptr< _Tp >::type; +}; +template < typename _Tp > class unique_ptr { +public: + using pointer = typename __uniq_ptr_impl< _Tp >::pointer; + unique_ptr(pointer); +}; +} // std +class wxRefCounter; +class wxObject { + virtual wxRefCounter CreateRefData(); + wxRefCounter *m_refData; +}; +class wxGDIObject : wxObject {}; +class wxFontBase : wxGDIObject {}; +class wxFont : wxFontBase {}; +class VisualTool { +protected: + VisualTool(int *, int *); +}; +class OpenGLText; +class VisualToolCross : VisualTool { + std::unique_ptr< OpenGLText > gl_text; + VisualToolCross(); +}; +class OpenGLText { // { dg-lto-warning "7: type 'struct OpenGLText' violates the C\\+\\+ One Definition Rule" } + float r, g, b, a; + int fontSize; + bool fontBold; + bool fontItalics; + std::basic_string< char > fontFace; + wxFont font; + int glyphs; +}; +int VisualToolCross_parent; +int VisualToolCross_context; +VisualToolCross::VisualToolCross() + : VisualTool(&VisualToolCross_parent, &VisualToolCross_context), + gl_text(0) {} diff --git a/gcc/testsuite/g++.dg/lto/pr92609_1.C b/gcc/testsuite/g++.dg/lto/pr92609_1.C new file mode 100644 index 00000000000..4c65a6a4600 --- /dev/null +++ b/gcc/testsuite/g++.dg/lto/pr92609_1.C @@ -0,0 +1,58 @@ +namespace std { +inline namespace __cxx11 {} +template < typename _Default > struct __detector { using type = _Default; }; +template < typename _Default, template < typename > class > +using __detected_or = __detector< _Default >; +template < typename _Default, template < typename > class _Op > +using __detected_or_t = typename __detected_or< _Default, _Op >::type; +template < typename > class allocator; +template < class > struct char_traits; +namespace __cxx11 { +template < typename _CharT, typename = char_traits< _CharT >, + typename = allocator< _CharT > > +class basic_string; +} +struct __allocator_traits_base { + template < typename _Tp > using __pointer = typename _Tp::pointer; +}; +struct allocator_traits : __allocator_traits_base { + using pointer = __detected_or_t< char *, __pointer >; +}; +namespace __cxx11 { +template < typename, typename, typename > class basic_string { + struct _Alloc_hider { + allocator_traits::pointer _M_p; + } _M_dataplus; + unsigned long _M_string_length; + enum { _S_local_capacity = 15 }; + union { + char _M_local_buf[_S_local_capacity + 1]; + unsigned long _M_allocated_capacity; + }; +}; +} // __cxx11 +} // std +class wxRefCounter; +class wxObject { + virtual int GetClassInfo(); + wxRefCounter *m_refData; +}; +class wxGDIObject : wxObject {}; +class wxFontBase : wxGDIObject {}; +class wxFont : wxFontBase {}; +template < class > class map {}; +namespace { +struct OpenGLTextGlyph; +} +typedef map< OpenGLTextGlyph > glyphMap; +class OpenGLText { + float r, g, b, a; + int fontSize; + bool fontBold; + bool fontItalics; + std::basic_string< char > fontFace; + wxFont font; + glyphMap glyphs; + OpenGLText(); +}; +OpenGLText::OpenGLText() {}