https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81882

            Bug ID: 81882
           Summary: attribute ifunc documentation uses invalid code
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

The documentation of the ifunc ("resolver") attribute in the GCC manual isn't
quite correct.  It advises users to declare the resolver to return a pointer to
a void function returning void, and shows an example of how to do that, like
so:

typedef __SIZE_TYPE__  size_t;

void* my_memcpy (void *dst, const void *src, size_t len)
{
  // ...
  return dst;
}

static void (*resolve_memcpy (void)) (void)
{
  return my_memcpy; // we'll just always select this routine
}

But the example returns the address of a function of incompatible type, which
then causes compilation warnings in C and errors in C++ (see below).

Instead, the resolver should be declared to return a pointer to the a function
of the same type as whose address it returns.

x.c: In function ‘resolve_memcpy’:
x.c:10:10: warning: returning ‘void * (*)(void *, const void *, size_t) {aka
void * (*)(void *, const void *, long unsigned int)}’ from a function with
incompatible return type ‘void (*)(void)’ [-Wincompatible-pointer-types]
   return my_memcpy; // we'll just always select this routine
          ^~~~~~~~~
At top level:
x.c:8:15: warning: ‘resolve_memcpy’ defined but not used [-Wunused-function]
 static void (*resolve_memcpy (void)) (void)
               ^~~~~~~~~~~~~~

Reply via email to