From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19632 invoked by alias); 22 Jul 2014 17:10:11 -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 19607 invoked by uid 89); 22 Jul 2014 17:10:10 -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:10:08 +0000 Received: from [10.10.3.121] (unknown [83.149.199.91]) by smtp.ispras.ru (Postfix) with ESMTP id 0BCFA224C1; Tue, 22 Jul 2014 21:10:04 +0400 (MSK) Date: Tue, 22 Jul 2014 17:18: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: <20140616085601.GA14894@kam.mff.cuni.cz> 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/msg01474.txt.bz2 On Mon, 16 Jun 2014, Jan Hubicka wrote: > > > /* 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_decl) > > > && (DECL_EXTERNAL (decl) || decl_replaceable_p (decl))) > > > return error_mark_node; > > > > > > Honza? > > > > Indeed, this may be a better place to do it as long as > > decl_replaceable_p reliably returns true for weak aliases. If so, the > > following might work: > > > > if ((!DECL_INITIAL (real_decl) && DECL_EXTERNAL (decl)) > > || decl_replaceable_p (decl))) > > return error_mark_node; > > > > On the other hand, I might just separate it out into two separate if > > statements since they should probably have their own comments. > > Yep, this looks like correct change. I used to have FIXME on this but > it seems it went away during some cleanups - the original condition was > comming from expmed's folding and indeed it looked unsafe to me. > > This change is OK with the testcase (if it passes testing) 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. OK for trunk/branch? 2014-07-22 Rich Felker Alexander Monakov gcc/ PR ipa/61144 * varpool.c (ctor_for_folding): Reject weak data. gcc/testsuite/ PR ipa/61144 * gcc.dg/special/wkali-3.c: New test. * gcc.dg/special/wkali-3a.c: Auxiliary file. diff --git a/gcc/varpool.c b/gcc/varpool.c index 04ce714..9ef2195 100644 --- a/gcc/varpool.c +++ b/gcc/varpool.c @@ -378,6 +378,9 @@ ctor_for_folding (tree decl) return error_mark_node; } + if (DECL_WEAK (decl) && !DECL_VIRTUAL_P (decl)) + return error_mark_node; + gcc_assert (TREE_CODE (decl) == VAR_DECL); real_node = node = varpool_get_node (decl); diff --git a/gcc/testsuite/gcc.dg/special/wkali-3.c b/gcc/testsuite/gcc.dg/special/wkali-3.c new file mode 100644 index 0000000..407ace6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/special/wkali-3.c @@ -0,0 +1,17 @@ +/* { dg-do run } */ +/* { dg-require-weak "" } */ +/* { dg-require-alias "" } */ +/* { dg-additional-sources "wkali-3a.c" } */ + +#include + +static const int dummy = 0; +extern const int foo __attribute__((__weak__, __alias__("dummy"))); + +int main(void) { + + if (foo) + exit(0); + else + abort(); +} diff --git a/gcc/testsuite/gcc.dg/special/wkali-3a.c b/gcc/testsuite/gcc.dg/special/wkali-3a.c new file mode 100644 index 0000000..b3bc6a4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/special/wkali-3a.c @@ -0,0 +1,3 @@ +/* { dg-do run } */ + +int foo = 1;