[Bug c/29186] optimzation breaks floating point exception flag reading

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Nov 9 12:41:20 GMT 2020


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

--- Comment #26 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Richard B. Kreckel from comment #25)
> (In reply to Richard Biener from comment #24)
> > So you're just lucky indeed ...
> 
> This makes me wonder if there is still a way to trigger this.
> 
> You suggest this has been fixed for the division (is there a PR or
> reference?) and I am not able to create a similar bug using addition,
> multiplication, etc. using GCC 10.

You just need to give GCC the incentive to break it.  Like with

#include <fenv.h>
#include <stdio.h>
int main()
{
   double x = (double)printf("") + 1.0; // one
   double y = (double)printf(""); // zero
   double breakme = x / y;
   feclearexcept(FE_ALL_EXCEPT);
   double z = x / y;  // should set FE_DIVBYZERO
   if (fetestexcept(FE_ALL_EXCEPT)) {
       printf("flag set after call.\n");
   }
   printf("%f/%f==%f\n",x,y,z + breakme);
}


More information about the Gcc-bugs mailing list