This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] proposed fix for bug # 61144
- From: Rich Felker <dalias at libc dot org>
- To: Alexander Monakov <amonakov at ispras dot ru>
- Cc: Jan Hubicka <hubicka at ucw dot cz>, Richard Biener <richard dot guenther at gmail dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 22 Jul 2014 13:23:47 -0400
- Subject: Re: [PATCH] proposed fix for bug # 61144
- Authentication-results: sourceware.org; auth=none
- References: <20140521015948 dot GA21600 at brightrain dot aerifal dot cx> <CAFiYyc0qj1Yc+VDchBYqsocT4aoyL01CMEB2LmzV3-=TcnHmBg at mail dot gmail dot com> <20140522035942 dot GG507 at brightrain dot aerifal dot cx> <20140616085601 dot GA14894 at kam dot mff dot cuni dot cz> <alpine dot LNX dot 2 dot 00 dot 1407222054570 dot 25299 at monopod dot intra dot ispras dot ru> <alpine dot LNX dot 2 dot 00 dot 1407222109050 dot 25299 at monopod dot intra dot ispras dot ru>
On Tue, Jul 22, 2014 at 09:17:12PM +0400, Alexander Monakov wrote:
> 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?
Why is this considered "replaceable"? That sounds like a bug to me.
Anyway, in looking for a solution, wouldn't it be helpful to look at
how this was treated in 4.8 and earlier, before bug 61144 was
introduced?
Rich