rejects-valid: analyzer imprecise-fp-arithmetic on valid code

Jonathan Wakely jwakely@redhat.com
Mon Apr 20 13:28:02 GMT 2026


On Mon, 20 Apr 2026 at 16:00 +0530, Mandar Kulkarni wrote:
>https://godbolt.org/z/h9a7x61nd
>#include <stdint.h>
>#include <stdlib.h>
>#include <math.h>
>#include <stdio.h>
>
>int main()
>{
>int num_entries = 100;
>float pruning_factor = 3.8f;
>// Apply pruning factor
>num_entries = ceilf(num_entries / pruning_factor);
>printf("num_entries: %d\n", num_entries);
>uint8_t* msg = (uint8_t*)calloc(1, num_entries);
>}
>
>gcc -fanalyzer t.c
><source>: In function 'int main()':
><source>:13:34: warning: use of floating-point arithmetic here might yield
>unexpected results [-Wanalyzer-imprecise-fp-arithmetic]
>   13 |   uint8_t* msg = (uint8_t*)calloc(1, num_entries);
>      |                            ~~~~~~^~~~~~~~~~~~~~~~
>  'int main()': event 1
>   13 |   uint8_t* msg = (uint8_t*)calloc(1, num_entries);
>      |                            ~~~~~~^~~~~~~~~~~~~~~~
>      |                                  |
>      |                                  (1) ⚠️  operand '2.63157902e+1f'
>is of type 'float'
><source>:13:34: note: only use operands of an integer type inside the size
>argument
>Compiler returned: 0

This mailing list is for automated email from our Bugzilla database,
not for reporting bugs.

Please report bugs to Bugzilla instead, as explained at https://gcc.gnu.org/bugs/

Thanks




More information about the Gcc-bugs mailing list