From patchwork Fri Dec 2 19:07:19 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Diego Novillo X-Patchwork-Id: 128937 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id E68E0B6F62 for ; Sat, 3 Dec 2011 06:07:41 +1100 (EST) Received: (qmail 21375 invoked by alias); 2 Dec 2011 19:07:39 -0000 Received: (qmail 21366 invoked by uid 22791); 2 Dec 2011 19:07:37 -0000 X-SWARE-Spam-Status: No, hits=-3.1 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-ey0-f201.google.com (HELO mail-ey0-f201.google.com) (209.85.215.201) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 02 Dec 2011 19:07:23 +0000 Received: by eaaq12 with SMTP id q12so98555eaa.2 for ; Fri, 02 Dec 2011 11:07:22 -0800 (PST) Received: by 10.14.2.15 with SMTP id 15mr942997eee.2.1322852842396; Fri, 02 Dec 2011 11:07:22 -0800 (PST) Received: by 10.14.2.15 with SMTP id 15mr942990eee.2.1322852842227; Fri, 02 Dec 2011 11:07:22 -0800 (PST) Received: from hpza9.eem.corp.google.com ([74.125.121.33]) by gmr-mx.google.com with ESMTPS id i11si6172576eea.0.2011.12.02.11.07.22 (version=TLSv1/SSLv3 cipher=AES128-SHA); Fri, 02 Dec 2011 11:07:22 -0800 (PST) Received: from wpaz9.hot.corp.google.com (wpaz9.hot.corp.google.com [172.24.198.73]) by hpza9.eem.corp.google.com (Postfix) with ESMTPS id EDDB75C0050; Fri, 2 Dec 2011 11:07:21 -0800 (PST) Received: from tobiano.tor.corp.google.com (tobiano.tor.corp.google.com [172.29.41.6]) by wpaz9.hot.corp.google.com with ESMTP id pB2J7J3B010305; Fri, 2 Dec 2011 11:07:19 -0800 Received: by tobiano.tor.corp.google.com (Postfix, from userid 54752) id 2F8DDAE1DE; Fri, 2 Dec 2011 14:07:19 -0500 (EST) To: reply@codereview.appspotmail.com, crowl@google.com, gcc-patches@gcc.gnu.org Subject: [pph] Cleanup to support namespace aliases (1/2) (issue5434109) Message-Id: <20111202190719.2F8DDAE1DE@tobiano.tor.corp.google.com> Date: Fri, 2 Dec 2011 14:07:19 -0500 (EST) From: dnovillo@google.com (Diego Novillo) X-System-Of-Record: true X-IsSubscribed: yes 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 This patch is part 1 of a cleanup needed to support namespace aliases. When processing a namespace aliase, we cannot access its binding level because it is NULL. Besides, it does not make sense to do anything with it, since the binding level for the original namespace would've been processed before. The creation of binding level on the reader is tripping us up because we end up with two binding levels for the same namespace. This is partially addressed in the next patch. Tested on x86_64. Diego. * pph-in.c (pph_in_bool): New. (pph_in_merge_key_namespace_decl): Factor out of ... (pph_in_merge_key_tree): ... here. Handle namespace aliases. * pph-out.c (pph_out_bool): New. (pph_out_merge_key_namespace_decl): Factor out of ... (pph_out_merge_key_tree): ... here. Handle namespace aliases. diff --git a/gcc/cp/pph-in.c b/gcc/cp/pph-in.c index 73c93df..088c1a2 100644 --- a/gcc/cp/pph-in.c +++ b/gcc/cp/pph-in.c @@ -210,6 +210,17 @@ pph_in_bitpack (pph_stream *stream) } +/* Read a boolean value from STREAM. */ + +static inline bool +pph_in_bool (pph_stream *stream) +{ + unsigned val = pph_in_uint (stream); + gcc_assert (val <= 1); + return (bool) val; +} + + /******************************************************** source information */ @@ -1575,7 +1586,7 @@ pph_in_lang_specific (pph_stream *stream, tree decl) } -/* Read language specific data in DECL from STREAM. */ +/* Read and merge language specific data in DECL from STREAM. */ static void pph_in_merge_lang_specific (pph_stream *stream, tree decl) @@ -2223,6 +2234,40 @@ pph_in_tree_header (pph_stream *stream, enum LTO_tags tag) } +/* Read all the merge keys for the names under namespace DECL from + STREAM. */ + +static void +pph_in_merge_key_namespace_decl (pph_stream *stream, tree decl) +{ + bool is_namespace_alias; + + /* If EXPR is a namespace alias, we do not need to merge + its binding level (namespaces aliases do not have a + binding level, they use the one from the namespace they + alias). */ + is_namespace_alias = pph_in_bool (stream); + if (!is_namespace_alias) + { + cp_binding_level *bl; + + if (DECL_LANG_SPECIFIC (decl)) + /* Merging into an existing namespace. */ + bl = NAMESPACE_LEVEL (decl); + else + { + /* This is a new namespace. Allocate a lang_decl and a binding + level to DECL. */ + retrofit_lang_decl (decl); + bl = ggc_alloc_cleared_cp_binding_level (); + NAMESPACE_LEVEL (decl) = bl; + } + + pph_in_binding_merge_keys (stream, bl); + } +} + + /* Read a merge key from STREAM. If the merge key read from STREAM is not found in *CHAIN, the newly allocated tree is added to it. */ @@ -2268,20 +2313,7 @@ pph_in_merge_key_tree (pph_stream *stream, tree *chain) if (DECL_P (expr)) { if (TREE_CODE (expr) == NAMESPACE_DECL) - { - cp_binding_level *bl; - if (DECL_LANG_SPECIFIC (expr)) - /* Merging into an existing namespace. */ - bl = NAMESPACE_LEVEL (expr); - else - { - /* This is a new namespace. */ - retrofit_lang_decl (expr); - bl = ggc_alloc_cleared_cp_binding_level (); - NAMESPACE_LEVEL (expr) = bl; - } - pph_in_binding_merge_keys (stream, bl); - } + pph_in_merge_key_namespace_decl (stream, expr); #if 0 /* FIXME pph: Disable type merging for the moment. */ else if (TREE_CODE (expr) == TYPE_DECL) diff --git a/gcc/cp/pph-out.c b/gcc/cp/pph-out.c index a4035f1..e1e21b9 100644 --- a/gcc/cp/pph-out.c +++ b/gcc/cp/pph-out.c @@ -168,6 +168,15 @@ pph_out_bitpack (pph_stream *stream, struct bitpack_d *bp) } +/* Write a boolean value VAL to STREAM. */ + +static inline void +pph_out_bool (pph_stream *stream, bool val) +{ + pph_out_uint (stream, val ? 1 : 0); +} + + /******************************************************** source information */ @@ -2123,6 +2132,24 @@ pph_out_merge_name (pph_stream *stream, tree expr) } +/* Write merge information for a namespace DECL to STREAM. */ + +static void +pph_out_merge_key_namespace_decl (pph_stream *stream, tree decl) +{ + bool is_namespace_alias; + + gcc_assert (TREE_CODE (decl) == NAMESPACE_DECL); + + /* If EXPR is a namespace alias, it will not have an associated + binding. In that case, tell the reader not to bother with it. */ + is_namespace_alias = (DECL_NAMESPACE_ALIAS (decl) != NULL_TREE); + pph_out_bool (stream, is_namespace_alias); + if (!is_namespace_alias) + pph_out_binding_merge_keys (stream, NAMESPACE_LEVEL (decl)); +} + + /* Write the merge key for tree EXPR to STREAM. */ static void @@ -2144,7 +2171,7 @@ pph_out_merge_key_tree (pph_stream *stream, tree expr) if (DECL_P (expr)) { if (TREE_CODE (expr) == NAMESPACE_DECL) - pph_out_binding_merge_keys (stream, NAMESPACE_LEVEL (expr)); + pph_out_merge_key_namespace_decl (stream, expr); #if 0 /* FIXME pph: Distable tree merging for the moment. */ else if (TREE_CODE (expr) == TYPE_DECL)