From patchwork Thu Jul 18 11:45:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 1133684 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-505268-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="bf7NVdtb"; 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 45qC5G5J55z9s8m for ; Thu, 18 Jul 2019 21:46:03 +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=ZB4LMX+7XDxbtwk0KTmnLYHVu1H8bUmN0iuWEgyxynsIMcAVFJdLt jrT2LH7TYltN/OGtW2XPvI0BRjATjIjvkLdGVtO2PvsUqzxpPMh71a8v3u2XYD5Q Mxw73uH491dXGXJSOJaMhZgo6Gl5KLtkTKsWj8fEfl+xOAUdHlpRqQ= 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=eJVykFwHVWqgqHpodTgPfUuiUps=; b=bf7NVdtbkcrbZpCioSxN RkgVJCe01dqBjGmr6T0RFRqLIiuQaI84RWycBymN0ja5J+arTNVXuyisE9tZKZmV H5z+/Dv2IoBr5GoAUYfUY4ljTDriEYSDlWUDrGvMa3yIVBIAEFw9Oe0sZM2nMfPt RVm99YXTuT6yKk0LyjK0ljg= Received: (qmail 118138 invoked by alias); 18 Jul 2019 11:45: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 118045 invoked by uid 89); 18 Jul 2019 11:45:44 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS autolearn=ham version=3.3.1 spammy=tus, Anonymous, pq, H*Ad:U*d 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; Thu, 18 Jul 2019 11:45:42 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id A23392825FC; Thu, 18 Jul 2019 13:45:34 +0200 (CEST) Date: Thu, 18 Jul 2019 13:45:34 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org, d@dcepelik.cz, rguenther@suse.de Subject: Improve TBAA for types in anonymous namespaces Message-ID: <20190718114534.xlzz2csojy5zd43z@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) Hi, this patch adjusts LTO tree merging to treat anonymous namespace types as local to a given TU, so just like !TREE_PUBLIC decls they are not merged (this is unify_scc change). This makes them to get different canonical types and act as independent types for TBAA. I also modified canonical type calculation to never consider anonymous namespace types as interoperable with structurally equivalent types declared in non-C++ translation units. Both these changes are tested by the testcase (first change makes set1 and set2 independent and second chnage makes set1&set2 independent of set3). lto-bootstrapped/regtested x86_64-linux Honza * lto-common.c (gimple_register_canonical_type_1): Do not look for non-ODR conflicts of types in anonymous namespaces. (unify_scc): Do not merge anonymous namespace types. * g++.dg/lto/alias-5_0.C: New testcase. * g++.dg/lto/alias-5_1.C: New. * g++.dg/lto/alias-5_2.c: New. Index: lto/lto-common.c =================================================================== --- lto/lto-common.c (revision 273551) +++ lto/lto-common.c (working copy) @@ -418,13 +418,19 @@ gimple_register_canonical_type_1 (tree t if (RECORD_OR_UNION_TYPE_P (t) && odr_type_p (t) && !odr_type_violation_reported_p (t)) { - /* Here we rely on fact that all non-ODR types was inserted into - canonical type hash and thus we can safely detect conflicts between - ODR types and interoperable non-ODR types. */ - gcc_checking_assert (type_streaming_finished - && TYPE_MAIN_VARIANT (t) == t); - slot = htab_find_slot_with_hash (gimple_canonical_types, t, hash, - NO_INSERT); + /* Anonymous namespace types never conflict with non-C++ types. */ + if (type_with_linkage_p (t) && type_in_anonymous_namespace_p (t)) + slot = NULL; + else + { + /* Here we rely on fact that all non-ODR types was inserted into + canonical type hash and thus we can safely detect conflicts between + ODR types and interoperable non-ODR types. */ + gcc_checking_assert (type_streaming_finished + && TYPE_MAIN_VARIANT (t) == t); + slot = htab_find_slot_with_hash (gimple_canonical_types, t, hash, + NO_INSERT); + } if (slot && !TYPE_CXX_ODR_P (*(tree *)slot)) { tree nonodr = *(tree *)slot; @@ -1640,11 +1646,14 @@ unify_scc (class data_in *data_in, unsig tree t = streamer_tree_cache_get_tree (cache, from + i); scc->entries[i] = t; /* Do not merge SCCs with local entities inside them. Also do - not merge TRANSLATION_UNIT_DECLs. */ + not merge TRANSLATION_UNIT_DECLs and anonymous namespace types. */ if (TREE_CODE (t) == TRANSLATION_UNIT_DECL || (VAR_OR_FUNCTION_DECL_P (t) && !(TREE_PUBLIC (t) || DECL_EXTERNAL (t))) - || TREE_CODE (t) == LABEL_DECL) + || TREE_CODE (t) == LABEL_DECL + || (TYPE_P (t) + && type_with_linkage_p (TYPE_MAIN_VARIANT (t)) + && type_in_anonymous_namespace_p (TYPE_MAIN_VARIANT (t)))) { /* Avoid doing any work for these cases and do not worry to record the SCCs for further merging. */ Index: testsuite/g++.dg/lto/alias-5_0.C =================================================================== --- testsuite/g++.dg/lto/alias-5_0.C (nonexistent) +++ testsuite/g++.dg/lto/alias-5_0.C (working copy) @@ -0,0 +1,35 @@ +/* { dg-lto-do run } */ +/* { dg-lto-options { { -O3 -flto } } } */ +/* This testcase tests that anonymous namespaces in different TUs are treated + as different types by LTO TBAA and that they never alias with structurally + same C types. */ +namespace { + __attribute__((used)) + struct a {int a;} *p,**ptr=&p; +}; +void +set1() +{ + *ptr=0; +} +void +get1() +{ + if (!__builtin_constant_p (*ptr==0)) + __builtin_abort (); +} +extern void set2(); +extern "C" void set3(); +int n = 1; +int +main() +{ + for (int i = 0; i < n; i++) + { + set1(); + set2(); + set3(); + get1(); + } + return 0; +} Index: testsuite/g++.dg/lto/alias-5_1.C =================================================================== --- testsuite/g++.dg/lto/alias-5_1.C (nonexistent) +++ testsuite/g++.dg/lto/alias-5_1.C (working copy) @@ -0,0 +1,9 @@ +namespace { + __attribute__((used)) + struct a {int a;} *p,**ptr=&p,q; +}; +void +set2() +{ + *ptr=&q; +} Index: testsuite/g++.dg/lto/alias-5_2.c =================================================================== --- testsuite/g++.dg/lto/alias-5_2.c (nonexistent) +++ testsuite/g++.dg/lto/alias-5_2.c (working copy) @@ -0,0 +1,7 @@ + __attribute__((used)) + struct a {int a;} *p,**ptr=&p,q; +void +set3() +{ + *ptr=&q; +}