On Tue, May 13, 2014 at 07:08:01PM +0200, Marek Polacek wrote:
> In essence, the gist of this instrumentation is:
> if (x u<= TYPE_MIN - 1.0 || x u>= TYPE_MAX + 1.0)
>   __ubsan_builtin ();
> this checks even +-Inf for free, and because the comparison is
> unordered, it detects even NaNs.
> 
> The question is how this should interact with feenableexcept (FE_INVALID)
> - currently it in some cases raises the Floating point exception, so I
> didn't include that in the testsite...  I don't know floating-point
> stuff well enough to judge what would be best.

What kind of exceptions do you get and where?  For sNaN I guess an exception
should be expectable, not sure if we raise one when casting sNaN to integer
without instrumentation.

> --- gcc/testsuite/c-c++-common/ubsan/float-cast-overflow-1.c
> +++ gcc/testsuite/c-c++-common/ubsan/float-cast-overflow-1.c
> @@ -0,0 +1,244 @@
> +/* { dg-do run } */

I'd say you should limit the test to ilp32 || lp64 targets.

> +/* { dg-options "-fsanitize=float-cast-overflow" } */
> +/* { dg-additional-options "-msse -mfpmath=sse" { target { { i?86-*-* 
> x86_64-*-* } && ia32 } } } */

And this needs to be guarded by && sse2_runtime.  Supposedly
you should also pass -msse2 rather than -msse, the test uses double
rather than float.

        Jakub

Reply via email to