public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jan Hubicka <hubicka@ucw.cz>
To: Rich Felker <dalias@libc.org>
Cc: Jan Hubicka <hubicka@ucw.cz>,
	Alexander Monakov <amonakov@ispras.ru>,	Jeff Law <law@redhat.com>,
	Richard Biener <richard.guenther@gmail.com>,
	GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] proposed fix for bug # 61144
Date: Mon, 16 Jun 2014 16:05:00 -0000	[thread overview]
Message-ID: <20140616160519.GB12467@kam.mff.cuni.cz> (raw)
In-Reply-To: <20140616133829.GY179@brightrain.aerifal.cx>

> On Mon, Jun 16, 2014 at 11:06:04AM +0200, Jan Hubicka wrote:
> > > 
> > > Are the attached files acceptable?
> > 
> > The testcase looks OK to me, but it already should be fixed on mainline
> > by patch https://gcc.gnu.org/ml/gcc-patches/2014-05/msg01315.html that
> > prevents dummy to be marked as constant. 
> > 
> > You can however modify the testcase to have
> > __attribute__ ((weak)) const int foo=0;
> 
> And the same for weak alias rather than straight weak definition like
> the above?

Yes, if you add const to your testcase, it will get miscompiled by mainline
again. 
> 
> > This needs your decl_replaceable change to not be optimized to if (0),
> > because of the explicit const modifier.
> 
> The case I care about actually has "dummy" as const (with the intent
> that it be allocated in a read-only section if the dummy definition is
> used). So for me it's important that this regression be fixed too.

Yep, GCC since 90's was optimizing reads from weak const attributes, but it
because worse because I added code walking through aliases.
> 
> > I did not change ctor_for_folding to reject variables above as I was not quite
> > sure we want to support this kind of interposition and I am still not quite certain.
> > C++ is quite clear about the transformation replacing initialized const by its value.
> 
> My concern is about C, not C++. This kind of interposition has always
> been supported in unix C, even prior to GCC, going back to sysv or
> earlier, as a documented feature (historically #pragma weak). It
> should not regress. If fixing it results in an regression with regards
> to optimizability of C++, perhaps this could be made
> language-specific, or (better) the C++ front-end could add an
> additional internal-use-only attribute to weak definitions it
> generates internally that permits constant-folding them, while not
> breaking the semantics for weak definitions provided by the user at
> the source level.

Yes, I see your point and clearly we should not optimize with explicit weak attribute.
I wonder if decl_replaceable_p is however correct check here or if we want explicit check
for weak visibility.

I am concerned about const variables w/o weak attribute with -fPIC (because for
those decl_replaceable_p returns true, too). Consider following testcase:
struct t
{
static const int dummy=0;
const int *m();
} t;
int
main()
{
  return *t.m();
}
int
main2()
{
  return t.dummy;
}
const int *
t::m()
{
  return &dummy;
}

Here main2 is optimized by C++ FE to return 0, while backend is affraid to optimize
main() after inlining anticipating that dummy may be interposed. However moving t::m
inside of the unit will make dummy comdat and it will get optimizing.
Adding another method and keying the t into other unit will make it optimized, too.

This is not very consistent. But perhaps we need a flag from C++ FE to tell us
what variables may not be interposed, because perhaps the c variant with -fPIC
const int dummy=0;
int
main()
{
  return t;
}

Jason?

A C variant of the testcase:

const int dummy=0;

const static int * d=&dummy;
int
main()
{
  return dummy;
}
int
main2()
{
  return *d;
}

seems optimized to return 0 (with -fPIC) for ages, too, but here at least
frontend won't substitute first dummy for 0.

Honza

  reply	other threads:[~2014-06-16 16:05 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-21  1:59 Rich Felker
2014-05-21  9:17 ` Richard Biener
2014-05-22  3:59   ` Rich Felker
2014-05-23 18:26     ` Jeff Law
2014-06-06 17:14       ` Rich Felker
2014-06-09 11:41         ` Alexander Monakov
2014-06-09 18:46           ` Rich Felker
2014-06-16  9:06             ` Jan Hubicka
2014-06-16 13:38               ` Rich Felker
2014-06-16 16:05                 ` Jan Hubicka [this message]
2014-06-16 16:35                   ` Rich Felker
2014-06-14 21:24           ` Rich Felker
2014-06-16  8:56     ` Jan Hubicka
2014-07-22 17:18       ` Alexander Monakov
2014-07-22 17:23         ` Alexander Monakov
2014-07-22 17:30           ` Rich Felker
2014-07-23  9:06           ` Florian Weimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140616160519.GB12467@kam.mff.cuni.cz \
    --to=hubicka@ucw.cz \
    --cc=amonakov@ispras.ru \
    --cc=dalias@libc.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=law@redhat.com \
    --cc=richard.guenther@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).