Bug 99784 - `labels as values`can point to the wrong spot after optimization
Summary: `labels as values`can point to the wrong spot after optimization
Status: RESOLVED DUPLICATE of bug 96956
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-03-26 07:19 UTC by Mike Hommey
Modified: 2021-03-26 07:55 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Hommey 2021-03-26 07:19:34 UTC
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!
Comment 1 Mike Hommey 2021-03-26 07:20:08 UTC
This is reproducible with all versions of GCC on godbolt, including trunk.
Comment 2 Andrew Pinski 2021-03-26 07:43:42 UTC
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 ***
Comment 3 Mike Hommey 2021-03-26 07:55:20 UTC
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.