[PATCH] correct documentation of attribute ifunc (PR 81882)

Martin Sebor msebor@gmail.com
Thu Aug 17 23:44:00 GMT 2017


On 08/17/2017 01:26 PM, Alexander Monakov wrote:
> On Thu, 17 Aug 2017, Martin Sebor wrote:
>
>>  returns a pointer to the selected implementation function.  The
>>  implementation functions' declarations must match the API of the
>> -function being implemented, the resolver's declaration is be a
>> -function returning pointer to void function returning void:
>> +function being implemented.  The resolver should be declared to
>> +be a function returning a pointer to a function taking no arguments
>> +and returning a pointer to a function of the same type as the
>> +implementation.  For example:
>
> The new wording is wrong (extra level of pointer-to-function).

You're right, that's a silly typo.  Thanks for catching it!
Here's what I meant to write:

   The resolver should be declared to be a function taking no
   arguments and returning a pointer to a function of the same
   type as the implementation.

Attached is an updated patch with the corrected wording.

> I suggest removing this part altogether, it's not useful at all,
> anyone writing the resolver can deduce what the return type should be
> based on the fact that a pointer to the implementation is returned.

I suppose that would work too.  If there's preference for
this approach I'm happy to remove the last sentence.

> (fwiw a simple 'void *' as return type would work in practice too)

Well, yes, it would work, but only about as well as the current
wording and example do.  I.e., it triggers (pedantic) warnings
in C and errors in C++.  To get around the errors, the usual
approach (despite what the manual says about returning a pointer
to a function) is to return void* and cast the address of the
function to it.  It would be helpful if users could avoid the
cast while at the same time having incompatibilities detected
for them.

(FWIW, I noticed this problem while testing an improvement
to have GCC do just that: detect invalid conversions in these
kinds of attributes (alias and ifunc) under bug 81854.)

Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcc-81882.diff
Type: text/x-patch
Size: 1681 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20170817/db3eee2b/attachment.bin>


More information about the Gcc-patches mailing list