From patchwork Wed Apr 18 11:31:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 900063 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-476543-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ucw.cz Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="HpL/CJoO"; 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 40R0MC0CZJz9s4l for ; Wed, 18 Apr 2018 21:31:50 +1000 (AEST) 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=jwJUEALOMwfJamqY6jwN1klMTIsfjtUannmHGM1oA7p3Agtn8N9mv ijzVyglpiCaZpzBpKsckFbzObAvadyNoUSX9YsPgtPQ02ECmUvjCWrnabFSgvp0O olzl6jmx64tMvWDx6iw1fbaFTnUyKBb/RC0lpvvx/rjh1GavR5MV28= 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=BavGLEwKgmjdZCIjQt8IjDT9nAs=; b=HpL/CJoOQ3RFQuP6gZn+ T5q29+aTfNxYTwk4bQx+CUFfJmEzj940jX37cLqlemXADyRrC5p0N3xTlxm4HN9D 3BS6+EpMSe3GlGEJCmOF9JxkKEYJl+jrCDoHfiRrUKH8nBfET9VM5rF4RPdWEHH0 7NSWyjU9FgNd78VJ39WTLfY= Received: (qmail 44812 invoked by alias); 18 Apr 2018 11:31:43 -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 44799 invoked by uid 89); 18 Apr 2018 11:31:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-9.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy=3, 7 X-HELO: nikam.ms.mff.cuni.cz Received: from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 18 Apr 2018 11:31:41 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 3B0E9542E56; Wed, 18 Apr 2018 13:31:38 +0200 (CEST) Date: Wed, 18 Apr 2018 13:31:38 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Do not forget to register ODR types to odr type hash Message-ID: <20180418113138.GE26063@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) Hi, this patch fixes misplaced conditional on TYPE_CANONICAL that makes odr_type_hash incomplete and thus we may miss some ODR warnings and/or diverge in devirtualization decisions. Bootstrapped/regtested x86_64-linux, also tested on libreoffice and firefox. Honza PR lto/85391 * lto.c (lto_read_decls): Do not test TYPE_CANONICAL before registering odr types. * g++.dg/lto/pr83121_0.C: Update template. * g++.dg/lto/pr83121_1.C: Update template. * g++.dg/lto/pr84805_0.C: Update template. * g++.dg/lto/pr84805_1.C: Update template. * g++.dg/lto/pr84805_2.C: Update template. Index: lto/lto.c =================================================================== --- lto/lto.c (revision 259434) +++ lto/lto.c (working copy) @@ -1772,12 +1772,13 @@ seen_type = true; num_prevailing_types++; lto_fixup_prevailing_type (t); - } - /* Compute the canonical type of all types. - ??? Should be able to assert that !TYPE_CANONICAL. */ - if (TYPE_P (t) && !TYPE_CANONICAL (t)) - { - gimple_register_canonical_type (t); + + /* Compute the canonical type of all types. + Because SCC components ar estreame in random (hash) order + we may have enountered the type before while registering + type canonical of a derived type in the same SCC. */ + if (!TYPE_CANONICAL (t)) + gimple_register_canonical_type (t); if (odr_type_p (t)) register_odr_type (t); } Index: testsuite/g++.dg/lto/pr83121_0.C =================================================================== --- testsuite/g++.dg/lto/pr83121_0.C (revision 259434) +++ testsuite/g++.dg/lto/pr83121_0.C (working copy) @@ -4,8 +4,8 @@ from being optimized away. */ struct Environment { // { dg-lto-warning "8: type 'struct Environment' violates the C\\+\\+ One Definition Rule" } - struct AsyncHooks { - int providers_[2]; // { dg-lto-message "a field of same name but different type is defined in another translation unit" } + struct AsyncHooks { // { dg-lto-warning "10: type 'struct AsyncHooks' violates the C\\+\\+ One Definition Rule" } + int providers_[2]; // { dg-lto-message "the first difference of corresponding definitions is field 'providers_'" } }; AsyncHooks async_hooks_; }; Index: testsuite/g++.dg/lto/pr83121_1.C =================================================================== --- testsuite/g++.dg/lto/pr83121_1.C (revision 259434) +++ testsuite/g++.dg/lto/pr83121_1.C (working copy) @@ -1,8 +1,8 @@ struct Environment { - struct AsyncHooks { // { dg-lto-warning "10: type 'struct AsyncHooks' violates the C\\+\\+ One Definition Rule" } - int providers_[1]; // { dg-lto-message "the first difference of corresponding definitions is field 'providers_'" } + struct AsyncHooks { + int providers_[1]; }; - AsyncHooks async_hooks_; + AsyncHooks async_hooks_; // { dg-lto-message "a field of same name but different type is defined in another translation unit" } }; void fn1() { Environment a; } int main () Index: testsuite/g++.dg/lto/pr84805_0.C =================================================================== --- testsuite/g++.dg/lto/pr84805_0.C (revision 259434) +++ testsuite/g++.dg/lto/pr84805_0.C (working copy) @@ -1,5 +1,5 @@ // { dg-lto-do link } -// { dg-lto-options {{-O2 -fPIC -shared -flto}} } +// { dg-lto-options {{-O0 -fPIC -shared -flto}} } template < typename _Tp, _Tp __v > struct integral_constant { static constexpr _Tp value = __v; @@ -9,7 +9,7 @@ struct is_void : __is_void_helper {}; template < typename > struct is_array : false_type {}; namespace __gnu_cxx { -enum _Lock_policy { _S_single, _S_mutex, _S_atomic }; +enum _Lock_policy { _S_single, _S_mutex, _S_atomic }; // { dg-lto-warning "6: type '_Lock_policy' violates the C\\+\\+ One Definition Rule" } const _Lock_policy __default_lock_policy = _S_atomic; } namespace std { using __gnu_cxx::_Lock_policy; @@ -21,7 +21,7 @@ bool = is_void::value > class __shared_ptr_access {}; template < typename _Tp, _Lock_policy _Lp > -class __shared_ptr : __shared_ptr_access< _Tp, _Lp > { +class __shared_ptr : __shared_ptr_access< _Tp, _Lp > { // { dg-lto-warning "7: type 'struct __shared_ptr' violates the C\\+\\+ One Definition Rule" } using element_type = _Tp; element_type *_M_ptr; __shared_count< _Lp > _M_refcount; @@ -88,7 +88,7 @@ class ExtSheetBuffer; class ExcelToSc; class XclImpColRowSettings; -struct RootData { +struct RootData { // { dg-lto-warning "8: type 'struct RootData' violates the C\\+\\+ One Definition Rule" } BiffTyp eDateiTyp; ExtSheetBuffer *pExtSheetBuff; SharedFormulaBuffer *pShrfmlaBuff; Index: testsuite/g++.dg/lto/pr84805_1.C =================================================================== --- testsuite/g++.dg/lto/pr84805_1.C (revision 259434) +++ testsuite/g++.dg/lto/pr84805_1.C (working copy) @@ -3,7 +3,7 @@ virtual ~XclRoot(); }; class XclImpRoot : XclRoot {}; -struct RootData { // { dg-lto-warning "8: type 'struct RootData' violates the C\\+\\+ One Definition Rule" } +struct RootData { XclImpRoot pIR; }; class ExcRoot { Index: testsuite/g++.dg/lto/pr84805_2.C =================================================================== --- testsuite/g++.dg/lto/pr84805_2.C (revision 259434) +++ testsuite/g++.dg/lto/pr84805_2.C (working copy) @@ -15,7 +15,7 @@ template < typename a, _Lock_policy, bool = g< a >::d, bool = t::d > class __shared_ptr_access {}; template < typename a, _Lock_policy l > -class __shared_ptr : __shared_ptr_access< a, l > { // { dg-lto-warning "7: type 'struct __shared_ptr' violates the C\\+\\+ One Definition Rule" } +class __shared_ptr : __shared_ptr_access< a, l > { using m = a; m *_M_ptr; __shared_count< l > _M_refcount; Index: testsuite/g++.dg/torture/pr43760.C =================================================================== --- testsuite/g++.dg/torture/pr43760.C (nonexistent) +++ testsuite/g++.dg/torture/pr43760.C (working copy) @@ -0,0 +1,40 @@ +typedef __builtin_va_list a; + +class b +{ +public: + virtual void c (int, const char *, a &); + char d; + void m_fn2 () + { + a a; + c (2, &d, a); + } +}; + +class e:b +{ + virtual void f () + { + } + void c (int, const char *, a &); +}; + +class g +{ +protected: + b h; +}; + +class i:g +{ + int j (); +}; + +int +i::j () +{ + h.m_fn2 (); + return 0; +} +