Re: GCC and division by 0 under sanitizers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Mar 29, 2020 at 05:01:39PM -0400, Jeffrey Walton via Gcc-help wrote:
> I'm having trouble with floating point arithmetic and division by 0.
> Undefined behavior sanitizer flags a division by 0 is a runtime error.

int f(int x) { return x / 0; }
float g(float x) { return x / 0; }

This actually warns during build for both functions:
$ gcc -Wall -W -O2 -fsanitize=undefined dz.c
dz.c: In function 'f':
dz.c:1:25: warning: division by zero [-Wdiv-by-zero]
    1 | int f(int x) { return x / 0; }
      |                         ^
dz.c: In function 'g':
dz.c:2:29: warning: division by zero [-Wdiv-by-zero]
    2 | float g(float x) { return x / 0; }
      |                             ^

but only f does anything with ubsan, as it should.  (Please open a PR
for the warning:
'-Wno-div-by-zero'
     Do not warn about compile-time integer division by zero.
     Floating-point division by zero is not warned about, as it can be a
     legitimate way of obtaining infinities and NaNs.
We clearly have a floating point division here.)

What do you do to see ubsan misfire?


Segher



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux