On Mon, 16 Jan 2012, Jakub Jelinek wrote:

> On Mon, Jan 16, 2012 at 09:35:08AM +0100, Richard Guenther wrote:
> > But that's of course intended.  Attributes or redirection on the
> > extern inline variant are completely meaningless.
> > 
> > > If you want to keep olddecl as is, then IMHO we should add a new bool
> > > argument to merge_decls and if the flag is set, make sure we only ever
> > > modify newdecl and not olddecl.
> > 
> > I don't think that is necesary nor warranted.  What legitimate use
> > would break you think?
> 
> The extern inline decl gets also all the previous decl attributes
> accumulated.  Asm redirection on the extern inline is meaningless.
> Consider:
> /* foo.h */
> extern int foo (int, int) __attribute__((regparm (2))) __asm ("bar");
> ...
> /* foo-inlines.h */
> extern inline __attribute__((gnu_inline, always_inline)) void
> foo (int x, int y)
> {
>   return something (x, y);
> }
> ...
> /* foo.c */
> int
> foo (int x, int y)
> {
>   return something (x, y);
> }
> 
> You really want to have __asm ("bar") on the foo out-of-line definition,
> wouldn't surprise me if this broke glibc or other packages that heavily
> use asm redirection (in glibc e.g. LFS).  And the regparm attribute
> is needed too.  The gnu_inline attribute isn't needed, but can be safely
> copied over and ignored, the always_inline attribute and maybe artificial
> attributes are the only ones that should be not copied over to the
> out-of-line definition.

Ok, I suppose that requires even more adjustments of the scope/lookup
stuff for extern inlines when we see the redefinition - thus, lookup
a previous decl and merge with that instead of doing no merging.
We don't seem to have a testcase for this at least.  I'll add yours
as follows (works with 4.6, fails with my patch)

extern int foo (int, int) __asm__ ("bar");
extern inline __attribute__((gnu_inline, always_inline)) int
foo (int x, int y)
{
  return 0;
}
int
foo (int x, int y)
{
  return 0;
}
int main()
{
  return bar ();
}

Before I spend too much time on this age-old bug - Joseph, can you
agree with the proposed partial fix sofar and then with looking
through the I_SYMBOL_BINDING chain to skip the extern inline decl
to find the decl to merge with?

Thanks,
Richard.

Reply via email to