<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/82910>82910</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang Static Analyzer has issues with handling floating-point numbers
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tianxinghe
</td>
</tr>
</table>
<pre>
version: clang17.0.1
It seems that CSA has problems handling floating-point operations.
https://godbolt.org/z/37T31jzY3
#include <stdio.h>
int llvm_fcmp_one(double X, double Y) {
int res = (X != Y && X == X && Y == Y);
return res;
}
int main(int argc, char ** argv) {
int *llvm_cbe_a46 = ((int *)/*NULL*/0);
if (llvm_fcmp_one(744753600, 41) != 0) {
printf("%d\n", *llvm_cbe_a46);
}
return 1;
}
When the formal parameter is of type int, the checker can correctly find the bug.
https://godbolt.org/z/xx769hYjo
#include <stdio.h>
int llvm_fcmp_one(int X, int Y) {
int res = (X != Y && X == X && Y == Y);
return res;
}
int main(int argc, char ** argv) {
int *llvm_cbe_a46 = ((int *)/*NULL*/0);
if (llvm_fcmp_one(744753600, 41) != 0) {
printf("%d\n", *llvm_cbe_a46);
}
return 1;
}
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsVMFu5DYM_Rr6QmQgy_bYPvjgzHSAAotetkUzp0CWaVupLBmSnCb5-kKeySabRYEceuhhLzJFkXyPxDOF92o0RA0Ut1AcE7GGybomKGGelBknSjrbPzeP5LyyBrIWpRZmTMsd26XAjsDay_lrQE80ewyTCHj42uIkPC7Odjp6J2F6rcyIg7YiKDPeLFaZgHYhJ4Kyxu8udaYQFg9ZC_wE_DTavrM67KwbgZ9egJ-y8vcsfXg5Z-_BERGBZ8pIvfaEkB186JXdTZD98hYR8bR-nO8HOS_31hDwqrdrpwnvgB_wap-B1wjlLb5lXnIdeYTsiMCrOwSeRvuMwPfA93gXn6Ln7tVzfvXEgpDdvi_nKKzOxIqQvQeC8vjucrEi9CyUAV5FU7hRRrZyEg6Bt8Db6Hu8sv5IGni79Sw7uhf5_rWBa7Etv95m3f72x5cv2_3EfiSshpj1cXplnpdFtmcsEsrTjcJlLux7OotTJgwbLgde9FAczGYePhL8Efq7mXwbXfoW9S3gcv45kcEwEQ7WzULjIpyYKZBD5dEOGJ4XiqOJ4DFMTiT_IodSGJTWOZJBP-OgTL89d-v4SWk-PZX7ejo_2P9GmtG36TIa_zdRXtF_6vLzukz6JuvrrBYJNWnJqirPS1YkU5OnMq-Hsh6KrOvyfZkXVUVin--LKu041YlqOOM547xgJStYsUtTOTDiVA9dV7OeQ85oFkrvIuOoyER5v1JT8TpliRYdab9teM639R1bLI6Ja2L8TbeOHnKmlQ_-rUJQQVNziOH4NYigJLZG6OcXcttq3xA8_q3C9K_b3axzR84nq9PNh79HhWntdtLOwE8R8_q5WZx9IBmAny4AwE9bF_8EAAD__xTs2Vo">