<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/95779>95779</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[lld] -flto=thin bug
</td>
</tr>
<tr>
<th>Labels</th>
<td>
lld
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
LukeSTM
</td>
</tr>
</table>
<pre>
gcc.c-torture/execute/execute8/pr17377.c
When I use the -flto=thin option to compile the following code, an error is reported when I run the generated binary. However, if the -flto=thin option is not added, the generated binary file is correct. Please check this out.
https://godbolt.org/z/r71arWT7s
```
#include <stdlib.h>
/* PR 、、target/17377
Bug in code emitted by "return" pattern on CRIS: missing pop of
forced return address on stack. */
/* { dg-require-effective-target return_address } */
int calls = 0;
void *f (int) __attribute__ ((__noinline__));
void *
f (int i)
{
/* The code does a little brittle song and dance to trig the "return"
pattern instead of the function epilogue. This must still be a
leaf function for the bug to be exposed. */
if (calls++ == 0)
return __builtin_return_address (0);
switch (i)
{
case 1:
return f;
case 0:
return __builtin_return_address (0);
}
return 0;
}
int x;
void *y (int i) __attribute__ ((__noinline__,__noclone__));
void *
y (int i)
{
x = 0;
/* This must not be a sibling call: the return address must appear
constant for different calls to this function. Postincrementing x
catches otherwise unidentified multiple returns (e.g. through the
return-address register and then this epilogue popping the address
stored on stack in "f"). */
return (char *) f (i) + x++;
}
int
main (void)
{
void *v = y (4);
if (y (1) != f
/* Can't reasonably check the validity of the return address
above, but it's not that important: the test-case will probably
crash on the first call to f with the bug present, or it will
run wild including returning early (in y or here), so we also
try and check the number of calls. */
|| y (0) != v
|| y (3) != 0
|| y (-1) != 0
|| calls != 5)
abort ();
exit (0);
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVlFv2zoP_TXKC5EglpMmfshDmyz4BnwXGLYCewxkm7Z1p0i-Ep0099dfUI4Tt2u3AUFtV-QRRZ5DUYWga4u4Ecsnsd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