From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29734 invoked by alias); 22 Jul 2014 17:18:32 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 29711 invoked by uid 89); 22 Jul 2014 17:18:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: smtp.ispras.ru Received: from smtp.ispras.ru (HELO smtp.ispras.ru) (83.149.199.79) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 22 Jul 2014 17:18:29 +0000 Received: from [10.10.3.121] (unknown [83.149.199.91]) by smtp.ispras.ru (Postfix) with ESMTP id B3624224C1; Tue, 22 Jul 2014 21:18:26 +0400 (MSK) Date: Tue, 22 Jul 2014 17:23:00 -0000 From: Alexander Monakov To: Jan Hubicka cc: Rich Felker , Richard Biener , GCC Patches Subject: Re: [PATCH] proposed fix for bug # 61144 In-Reply-To: Message-ID: References: <20140521015948.GA21600@brightrain.aerifal.cx> <20140522035942.GG507@brightrain.aerifal.cx> <20140616085601.GA14894@kam.mff.cuni.cz> User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-SW-Source: 2014-07/txt/msg01475.txt.bz2 On Tue, 22 Jul 2014, Alexander Monakov wrote: > I'd like to push this topic forward a bit. I've bootstrapped and regtested a > version of the patch based on the initial proposal to check DECL_WEAK. The > approach with decl_replaceable_p looks not that easy; I'll expand in a > followup email. The problem with the patch below using decl_replaceable_p is that it regresses the following C++ testcase: struct z { static const int aaa = 1; }; //const int z::aaa; int foo(int x) { return x ? z::aaa : x; } Here decl_replaceable_p is 'true' for z::aaa. With the patch the reference to z::aaa is not folded, but its definition is not emitted either, so a undefined reference error is produced at link time. But naturally varpool_ctor_useable_for_folding_p for z::aaa must stay true in the first place. In a way z::aaa is "replaceable" in the sense that the compiler is not going to emit a definition, so if anything references z::aaa in the current translation unit (if the address is taken), the definition must come from another TU. Nevertheless, references to the value can be folded. I'm unsure what the correct test would look like. Any advice? Thanks. Alexander diff --git a/gcc/varpool.c b/gcc/varpool.c index b98fc1b..addbe6d 100644 --- a/gcc/varpool.c +++ b/gcc/varpool.c @@ -329,11 +329,13 @@ varpool_ctor_useable_for_folding_p (varpool_node *node) if (!TREE_READONLY (node->decl) && !TREE_READONLY (real_node->decl)) return false; - /* Variables declared 'const' without an initializer - have zero as the initializer if they may not be - overridden at link or run time. */ - if (!DECL_INITIAL (real_node->decl) - && (DECL_EXTERNAL (node->decl) || decl_replaceable_p (node->decl))) + /* Accept variables declared 'const' without an initializer (so they have + zero as the initializer), unless they may be overridden at link time. */ + if (!DECL_INITIAL (real_node->decl) && DECL_EXTERNAL (node->decl)) + return false; + + /* Reject initializers that can be overridden at link or run time. */ + if (decl_replaceable_p (node->decl)) return false; /* Variables declared `const' with an initializer are considered