https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101953

--- Comment #27 from Harald van Dijk <harald at gigawatt dot nl> ---
(In reply to jos...@codesourcery.com from comment #25)
> The option to use to detect this is -fsanitize=float-cast-overflow (note: 
> I haven't tested if it detects this particular case).  As per the manual: 
> "Unlike other similar options, @option{-fsanitize=float-cast-overflow} is 
> not enabled by @option{-fsanitize=undefined}.".  (Annex F makes the result 
> an unspecified value with "invalid" raised, instead of being undefined 
> behavior, which justifies not including it in -fsanitize=undefined by 
> default.

Have just tested that -fsanitize=float-cast-overflow does indeed catch this
case. Thanks for the explanation, that makes sense.

The fact that it's not included by -fsanitize=undefined even in compilations
where Annex F is not followed or does not apply is a bit weird, but changing it
to be included was bug #100591, closed as invalid; I won't open a new bug
asking for the same thing again.

(In reply to M W from comment #24)
> I know it is documented as "undefined," but it is also unexpected without
> even a warning.

Martin Sebor requested opening a new bug if you'd like to see a compile-time
warning for this, rather than tracking that as part of this bug.

(In reply to M W from comment #26)
> pi@raspberrypi:~ $ gcc -fsanitize=float-cast-overflow -Wall -o badpi badpi.c
> -lm
> pi@raspberrypi:~ $ 
> 
> That flag doesn't work

The flag does work, but it's a runtime warning, not a compile-time warning. Run
badpi and you should see it.

Reply via email to