-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Open
Description
bool xxxx();
int kkk()
{
return xxxx() + 1;
}https://godbolt.org/z/YoM1PYE1n
llvm:
kkk:
push {r11, lr}
bl xxxx
mov r1, #1
cmp r0, #0
movwne r1, #2
mov r0, r1
pop {r11, pc}
gcc:
kkk:
push {r4, lr}
bl xxxx
add r0, r0, #1
pop {r4, pc}
According to ARM's ABI (I'm not sure if there is documentation to support this, but both GCC and LLVM compilers behave this way), in the aforementioned use case, the return value of the bool type is stored in the r0 register, and the value of r0 is 0 (false) or 1 (true). This can be observed from the following use case: https://godbolt.org/z/Wj1Goq1Y4
However, the LLVM compiler seems to have missed some optimizations when performing arithmetic operations on return values.
No similar issues have been identified on other architectures at this time.