From patchwork Thu Sep 2 19:28:15 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 63518 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 785B7B717C for ; Fri, 3 Sep 2010 05:28:29 +1000 (EST) Received: (qmail 20090 invoked by alias); 2 Sep 2010 19:28:27 -0000 Received: (qmail 20081 invoked by uid 22791); 2 Sep 2010 19:28:26 -0000 X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL, BAYES_05, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from nikam-dmz.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 02 Sep 2010 19:28:19 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id E30B59AC93B; Thu, 2 Sep 2010 21:28:15 +0200 (CEST) Date: Thu, 2 Sep 2010 21:28:15 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org, rth@redhat.com, rguenther@suse.de Subject: [RFA] Avoid non-static&external vars in varpool Message-ID: <20100902192815.GN1664@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) 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 Hi, this patch fixes problem with gfortran adding local var into varpool. I first considered it to be bug in the frontend, but rest_of_decl_compilation comment seems to agree with fortran's behaviour: This is called from various places for FUNCTION_DECL, VAR_DECL, and TYPE_DECL nodes. This does nothing for local (non-static) variables, unless the variable is a register variable with DECL_ASSEMBLER_NAME set. In that case, or if the variable is not an automatic, it sets up the RTL and outputs any assembler code (label definition, storage allocation and initialization). So this patch makes it really no-op on local vars and also adds sanity check to varpool. Bootstrapped and regtested x86_64-linux, OK? Honza * passes.c (rest_of_decl_compilation): Do not add local vars into varpol. * varpool.c (varpool_get_node, varpool_node): Sanity check that only static or extern vars are in varpool. (varpool_finalize_decl): Sanity check that only static vars are finalized. Index: passes.c =================================================================== --- passes.c (revision 163779) +++ passes.c (working copy) @@ -219,7 +219,8 @@ rest_of_decl_compilation (tree decl, /* Let cgraph know about the existence of variables. */ if (in_lto_p && !at_end) ; - else if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl)) + else if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl) + && TREE_STATIC (decl)) varpool_node (decl); } Index: varpool.c =================================================================== --- varpool.c (revision 163779) +++ varpool.c (working copy) @@ -111,7 +111,8 @@ varpool_get_node (tree decl) { struct varpool_node key, **slot; - gcc_assert (DECL_P (decl) && TREE_CODE (decl) != FUNCTION_DECL); + gcc_assert (TREE_CODE (decl) == VAR_DECL + && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))); if (!varpool_hash) return NULL; @@ -129,7 +130,8 @@ varpool_node (tree decl) { struct varpool_node key, *node, **slot; - gcc_assert (DECL_P (decl) && TREE_CODE (decl) != FUNCTION_DECL); + gcc_assert (TREE_CODE (decl) == VAR_DECL + && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))); if (!varpool_hash) varpool_hash = htab_create_ggc (10, hash_varpool_node, @@ -365,6 +398,8 @@ varpool_finalize_decl (tree decl) { struct varpool_node *node = varpool_node (decl); + gcc_assert (TREE_STATIC (decl)); + /* The first declaration of a variable that comes through this function decides whether it is global (in C, has external linkage) or local (in C, has internal linkage). So do nothing more