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

--- Comment #4 from uecker at gcc dot gnu.org ---

I am not sure whether it is possible to trigger this problem in reasonable ways
without the new builtins. The fix would also fix PR99198, but this is not
useful code.


Fixing this would be a very useful, as it makes it possible to use nested
functions with regular callbacks that take a void * argument.

With my tentative fix (I haven't investigated fixing this properly), the nested
function becomes:

        testq   %rdi, %rdi
        cmove   %r10, %rdi
        movl    (%rdi), %eax
        ret

If one writes the condition as

        if (p != __builtin_call_static_chain(g))
                return __builtin_call_with_static_chain(g(p), p);

it becomes even optimal:

        movl    (%rdi), %eax
        ret



Someone (I forgot who) previously suggested a feature that allows one to
specify a regular argument that then is used for the static chain, which would
correspond to exactly this.

Reply via email to