<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/54328>54328</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
address of label is "1" when label has been optimized away
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kees
</td>
</tr>
</table>
<pre>
The value of a label address is changed to "1" when its basic block has been optimized away. This doesn't seem sensible, though I'm not sure what the "correct" behavior should be. I suspect the code at the label should not be elided? But that probably has a whole set of other problems.
Contrived example:
https://godbolt.org/z/G4hs55KrG
```
#include <stdio.h>
static __attribute__((noinline))
void set_return_addr(unsigned long *expected, unsigned long *addr)
{
/* Use of volatile is to make sure final write isn't seen as a dead store. */
unsigned long * volatile *ret_addr = (unsigned long **)__builtin_frame_address(0) + 1;
printf("*ret_addr:%p expected:%p replacement:%p\n", *ret_addr, expected, addr);
fflush(NULL);
/*
* If make sure we've found the right place on the stack before writing it.
* Then make sure Clang isn't giving us something weird.
*/
if (*ret_addr == expected && addr > (unsigned long *)1)
*ret_addr = addr;
else
printf("Didn't find expected return address on stack\n");
}
volatile int tricky;
int main(void)
{
#ifdef FORCE
if (tricky)
goto redirected;
#endif
set_return_addr(&&normal, &&redirected);
normal:
printf("I should be skipped\n");
return tricky;
redirected:
printf("Redirected\n");
return tricky;
}
```
GCC, -O2 will collapse the label to an earlier one:
```
*ret_addr:0x401069 expected:0x401060 replacement:0x401060
Didn't find expected return address on stack
I should be skipped
```
Clang, -O2:
```*ret_addr:0x4005d6 expected:0x4005d6 replacement:0x1
Didn't find expected return address on stack
I should be skipped
```
If an explicit path is kept, the label sticks around, as expected.
Clang, -O2 -DFORCE
```
*ret_addr:0x4005e4 expected:0x4005e9 replacement:0x4005e9
Didn't find expected return address on stack
I should be skipped
```
While it does seem better to avoid aliasing a different label (as GCC does) with a literal "1", it seems it'd be better to error out the compile since the label doesn't exist any more.
@nickdesaulniers
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy9Vltv4jgU_jXhxRoUkobLAw8tnVbVjnakUUf7iBxyQrw4dmQ70M6v389OSlJotZqXQSFg-1y_c_HJdfG6fq6IHblsiemScSZ5TpLxojBkLROW7Squ9lQwp1mUJDN82akixYSzLOdW7Fgu9e7AKo414UA3TtTiF1j4ib9O2XMFKYUmq6Jk4ZglqvFSVuSSomTDXKXbfcWecFozpUHRGoIO7nBEXulOG0M751XnVPGj0IZZcMkC6yl7AodtQBDod7og1vN2zvSkXnROjKQoqIjSB3bXeiqQNkbnPJevwQcO1VoSTHQeEQ05JlBIqu00iu-j-LZ7b7RyRhzhKL3wuoE3aX9SOddYv0oe8Ox1kWvpptrssfqF7-NNZbPsL_M4FhfN4_7plkkq1E628CZKN9YVQk-rKP06ZrGOOwRgu-UOluSto-02SpZ4lBZKCgWAV_4J1EctCu_W1pBrjdr6IIO0RSj2Cl5IrfaA-5ZePJjACMG5OuyYeonR4q77w_AJzt6ynzZk0lFL2AYcEXykTs0P1AW2FIpLdjLC-bNzTigWsC-Iw0anDeIKaV7mWcGVLYMSLOBU8Aho3bOP3ArParvNWyGdUNvS8Jq2faaDIcYp6O7YLErvxih73Y0RypUB22SkLMQ4a9gZsn5tqJF8RzUp129F2UYF3s3YWL8cw_2GbjrCtSxlayuo_vvnt2-Xhx3owzrA8lSO8D4hBxZH4K5bVYSqMGJfIem9gUyrsIVEQgnnVGrPgdgIYCbc9ELwsy_8QfRGck_WB3Evjp6rtczqmlzlFycSpriQ8i6momQB1Hfh8xF8QwXHczysP_v6SWhXs3NSsv5zmRNdvEbYkbT0nmUc5XtRdH4hYYvBnK52zg0S-AXszuEdwhMt7sdZNBSEQtsxYnd4PZP6rZoLSFj6Ir2uL98MyoJK9vD9x-brJXy9tEsA9hqFZ6gQps_NQRipQpSjLDr_u24PHf5Km5rLLnv9eiR27HJ497TpJ-XzNPRuZg-iaSDjGj3P1WN9AVb3Hvv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