https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101559
Bug ID: 101559 Summary: RISCV -- incorrect label address when using -O2 Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: joel.porquet at gmail dot com Target Milestone: --- The GNU construct `&&label` supposedly allows the programmer to get the address corresponding to a label. When compiling for RISCV, the correct address is computed when compiling with -O0 but not with -O2. Here is an example code where a label's address is properly computed: https://godbolt.org/z/qnEafeY6f. As you can see, the address corresponding to label `.L2` is properly retrieved using `lui` followed by `addi` and placed into register `a5`. Now, when the same code is compiled with `-O2`, the address is not properly computed: https://godbolt.org/z/n8zbbTnhb. As you can see, the label `.L2` is now placed at the very beginning of the function and points onto the function's first instruction. As a result, the computed address will not correspond to where the label was placed in the original code. Is that a bug, or am I missing something? Thanks!