https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117688
--- Comment #1 from Krister Walfridsson <kristerw at gcc dot gnu.org> ---
Interestingly, the function is generated correctly if x is passed as a function
argument:
__attribute__ ((noipa)) void
foo2 (int8_t x)
{
int8_t minus;
_Bool overflow = __builtin_sub_overflow (x, y, &minus);
result = overflow ? (x < 0 ? 0x80 : 0x7f) : minus;
}
The difference in the generated code is that GCC generates foo as if x were
unsigned, so code which for foo2 is generated as:
srai a3,a0,63
xori a4,a3,127
and a4,a4,a5
is for foo miscompiled as:
andi a4,a5,127