This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

asm in inline function invalidating function attributes?


I think gcc should allow the programmer to tell it something about a
function return value even if the function is inlined and the compiler
can see all the code.  Consider the code below.

If NOINLINE is defined the compiler will call g once.  No need to do
anything after the h() call since the function is marked const.

If NOINLINE is not defined and the compiler sees the asm statement it
will expand the function body twice.  Don't worry about the content of
the asm, this is correct in the case I care about.  What I expect is
that gcc still respects that the function is marked const and performs
the same optimization as in the case when the function is not inlined.

Is there anything I miss how to achieve this?  I don't think so in
which case, do people agree that this should be changed?


extern int **g(void) __attribute__((const, nothrow));
#ifndef NOINLINE
extern inline int ** __attribute__((always_inline, const, nothrow,
gnu_inline, artificial)) g(void) {
  int **p;
  asm ("call g@plt" : "=a" (p));
  return p;
}
#endif

#define pr(c) ((*g())[c] & 0x80)

extern void h(void);

int
f(const char *s)
{
  int c = 0;
  for (int i = 0; i < 20; ++i)
    c |= pr(s[i]);

  h();

  for (int i = 20; i < 40; ++i)
    c |= pr(s[i]);

  return c;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]