On Thu, Jul 19, 2018 at 01:39:04PM +0200, Florian Weimer wrote: > On 07/19/2018 01:33 PM, Jakub Jelinek wrote: > > On Thu, Jul 19, 2018 at 04:21:26AM -0700, H.J. Lu wrote: > > > The new indirect_return attribute is intended to mark swapcontext in > > > <ucontext.h>. This patch defines __HAVE_INDIRECT_RETURN_ATTRIBUTE__ > > > so that it can be used checked before using indirect_return attribute > > > in <ucontext.h>. It works when the indirect_return attribute is > > > backported to GCC 8. > > > > > > OK for trunk? > > > > No. Use > > #ifdef __has_attribute > > #if __has_attribute (indirect_return) > > ... > > #endif > > #endif > > instead, like for any other attribute. > > That doesn't work because indirect_return is not in the implementation > namespace and expanded in this context. I assume that __has_attribute > (__indirect_return__) would work, though. > > Could we add: > > #ifdef __has_attribute > # define __glibc_has_attribute(attr) __has_attribute (attr) > #else > # define __glibc_has_attribute 0 > #endif > > And then use this: > > #if __glibc_has_attribute (__indirect_return__) > > Would that still work? >
Both __has_attribute (indirect_return) and __has_attribute (__indirect_return__) work here. H.J. --- The new indirect_return attribute is intended to mark swapcontext in <ucontext.h>. Test __has_attribute (indirect_return) so that it can be backported to GCC 8. PR target/86560 * gcc.target/i386/pr86560-4.c: New test. * gcc.target/i386/pr86560-5.c: Likewise. --- gcc/testsuite/gcc.target/i386/pr86560-4.c | 21 +++++++++++++++++++++ gcc/testsuite/gcc.target/i386/pr86560-5.c | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 gcc/testsuite/gcc.target/i386/pr86560-4.c create mode 100644 gcc/testsuite/gcc.target/i386/pr86560-5.c diff --git a/gcc/testsuite/gcc.target/i386/pr86560-4.c b/gcc/testsuite/gcc.target/i386/pr86560-4.c new file mode 100644 index 00000000000..a623e3dcbeb --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr86560-4.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fcf-protection" } */ +/* { dg-final { scan-assembler-times {\mendbr} 2 } } */ + +struct ucontext; + +extern int (*bar) (struct ucontext *) +#ifdef __has_attribute +# if __has_attribute (indirect_return) + __attribute__((__indirect_return__)) +# endif +#endif +; + +extern int res; + +void +foo (struct ucontext *oucp) +{ + res = bar (oucp); +} diff --git a/gcc/testsuite/gcc.target/i386/pr86560-5.c b/gcc/testsuite/gcc.target/i386/pr86560-5.c new file mode 100644 index 00000000000..33b0f6424c2 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr86560-5.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fcf-protection" } */ +/* { dg-final { scan-assembler-times {\mendbr} 2 } } */ + +struct ucontext; + +extern int (*bar) (struct ucontext *) +#ifdef __has_attribute +# if __has_attribute (__indirect_return__) + __attribute__((__indirect_return__)) +# endif +#endif +; + +extern int res; + +void +foo (struct ucontext *oucp) +{ + res = bar (oucp); +} -- 2.17.1