<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/85018>85018</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
bool* is optimised too aggressively under assumption that byte value is 0 or 1
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hnarkaytis
</td>
</tr>
</table>
<pre>
https://godbolt.org/z/hcKre8ETY
I want to write a function that takes a pointer on boolean and return integer value 0 for false and 1 for true.
int bool2int1 (bool * b) { return (*b ? 1 : 0); }
Optimisation with -O2 and -O3 returns byte value of input pointer even though value might be other then 0 and 1
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxcUr2O2zwQfJpVs7BBUr8uVPhwn4APKdykSUlJK4k5mhTIpQ3n6QPpnJyRhsRil7Mzw9ExmtkRtVC-Qfme6cSLD-3idPjQDzYx6_34aBfmNUJ-BtWB6mY_9t7y0YcZVPcLVLcM3wI1_33_AeIdxPnz_B_v2jGyx3swTKhxSm5g4x3yohlZf1BEjas3jimgd9h7b0k71G7EQJyCw603U8CbtolQ4OQDTtpG2ofkXnNIdHxdbRzvWMo4lgiq2QoEdcYe1AmhfvsDD6oBde4R8g4lQn5GAeoE-RtC_f4KeVnZXE3UO_-74QUPF7VzOFzyJ1rE_sH0pOonNG5N_Fcf3WhT7tO8PEeuZl4Ye0LPCwXkhRyKp67X3dnY5uMpP-mMWllLkQtVyipb2r4ual0NcqrKRlTT0MiSxqbKCyEqWeRDZlolVCFymYtCyLI6kuiFJtmUw1TURd1AIeiqjT1ae7tuP5qZGBO1TSlkk1ndk417OJRydMe9CUptWQnt9ubQpzlCIayJHL9Q2LCldrN9c91E9J_-0YjsPep5DhSjuZF9YHIjBdQxpuv6FY8XK01EgT6gxCwF-28aDS-pPw7-Cqrb9j-vwxr8TxoYVLezjqC6XdXvAAAA___ag_G8">