Reduced testcase: ``` extern void bar(); extern void qux(void*); void foo() { bar(); here: qux(&&here); } ``` Resulting code at -O2: ``` foo(): .LFB0: .L2: sub rsp, 8 call bar() .LVL0: mov edi, OFFSET FLAT:.L2 add rsp, 8 jmp qux(void*) ``` IOW, the pointer that qux gets is that of a location before the call to bar!
This is reproducible with all versions of GCC on godbolt, including trunk.
Dup of bug 96956. This is undefined. See PR 96956 for the reason why. *** This bug has been marked as a duplicate of bug 96956 ***
PR 96956 only really talks about this: "You may not use this mechanism to jump to code in a different function. If you do that, totally unpredictable things happen.". My testcase doesn't involve jumping to the address.