Re: [PATCH] Implement -fsanitize=float-cast-overflow (take 3)

2014-05-23 Thread Konstantin Serebryany
On Fri, May 23, 2014 at 6:35 PM, Konstantin Serebryany wrote: > On Fri, May 23, 2014 at 6:28 PM, Jakub Jelinek wrote: >> On Fri, May 23, 2014 at 04:19:00PM +0200, Marek Polacek wrote: >>> This is the latest patch for -fsanitize=float-cast-overflow. Since last >>> version it: >>> - adds tons of t

Re: [PATCH] Implement -fsanitize=float-cast-overflow (take 3)

2014-05-23 Thread Konstantin Serebryany
On Fri, May 23, 2014 at 6:28 PM, Jakub Jelinek wrote: > On Fri, May 23, 2014 at 04:19:00PM +0200, Marek Polacek wrote: >> This is the latest patch for -fsanitize=float-cast-overflow. Since last >> version it: >> - adds tons of tests written by Jakub; >> - patches libubsan so it can handle 96-bit

Re: [PATCH] Implement -fsanitize=float-cast-overflow (take 3)

2014-05-23 Thread Jakub Jelinek
On Fri, May 23, 2014 at 04:19:00PM +0200, Marek Polacek wrote: > This is the latest patch for -fsanitize=float-cast-overflow. Since last > version it: > - adds tons of tests written by Jakub; > - patches libubsan so it can handle 96-bit floating-point types > (that is, long double and __float80

Re: [PATCH] Implement -fsanitize=float-cast-overflow (take 2)

2014-05-21 Thread Jakub Jelinek
On Wed, May 21, 2014 at 04:46:14PM +0200, Jakub Jelinek wrote: > Here is a testcase that (IMHO, not tested with your patch) should > test various boundary cases that shouldn't result in undefined behavior. > I've tried to keep it portable across various architectures, assumes > primarily two's comp

Re: [PATCH] Implement -fsanitize=float-cast-overflow (take 2)

2014-05-21 Thread Joseph S. Myers
On Wed, 21 May 2014, Marek Polacek wrote: > On Tue, May 20, 2014 at 09:50:10PM +, Joseph S. Myers wrote: > > On Tue, 20 May 2014, Marek Polacek wrote: > > > > > * is missing tests for long doubles/-mlong-double-128, > > > > Also missing tests for float - as far as I can see, only double is t

Re: [PATCH] Implement -fsanitize=float-cast-overflow (take 2)

2014-05-21 Thread Jakub Jelinek
On Wed, May 21, 2014 at 02:51:00PM +0200, Marek Polacek wrote: > On Tue, May 20, 2014 at 09:50:10PM +, Joseph S. Myers wrote: > > On Tue, 20 May 2014, Marek Polacek wrote: > > > > > * is missing tests for long doubles/-mlong-double-128, > > > > Also missing tests for float - as far as I can s

Re: [PATCH] Implement -fsanitize=float-cast-overflow (take 2)

2014-05-21 Thread Marek Polacek
On Tue, May 20, 2014 at 09:50:10PM +, Joseph S. Myers wrote: > On Tue, 20 May 2014, Marek Polacek wrote: > > > * is missing tests for long doubles/-mlong-double-128, > > Also missing tests for float - as far as I can see, only double is tested. > Ideally all of float, double, long double, _

Re: [PATCH] Implement -fsanitize=float-cast-overflow (take 2)

2014-05-20 Thread Joseph S. Myers
On Tue, 20 May 2014, Marek Polacek wrote: > * is missing tests for long doubles/-mlong-double-128, Also missing tests for float - as far as I can see, only double is tested. Ideally all of float, double, long double, __float128 (where supported), __float80 (where supported) would be tested (th

Re: [PATCH] Implement -fsanitize=float-cast-overflow (take 2)

2014-05-20 Thread Marek Polacek
Thanks for all your help. This is updated patch which: * uses mix/min handling that Jakub kindly wrote, * limited a test to ilp32 || lp64 + used sse2_runtime (but it's likely I screwed it up as usually), * adds a testcase for (unsigned) __int128, * adds testcases for C and C++ bit-fields, * mak

Re: [PATCH] Implement -fsanitize=float-cast-overflow

2014-05-16 Thread Joseph S. Myers
On Fri, 16 May 2014, Jakub Jelinek wrote: > has variable. Guess the combination of IBM long double and __int128_t > (for long long it is still ok) is rare enough that we don't need to care > about it (alternative would be e.g. to compare against addition of There are existing problems with that

Re: [PATCH] Implement -fsanitize=float-cast-overflow

2014-05-16 Thread Jakub Jelinek
On Thu, May 15, 2014 at 09:29:44PM +, Joseph S. Myers wrote: > On Thu, 15 May 2014, Jakub Jelinek wrote: > > > But I think we can't use decimal_real_from_string, we'd need a variant > > of that function that would allow specification of the rounding mode > > My point is that you can use "%.*RUe

Re: [PATCH] Implement -fsanitize=float-cast-overflow

2014-05-15 Thread Joseph S. Myers
On Thu, 15 May 2014, Jakub Jelinek wrote: > But I think we can't use decimal_real_from_string, we'd need a variant > of that function that would allow specification of the rounding mode My point is that you can use "%.*RUe" or "%.*RDe" formats (for max and min respectively), with an appropriate

Re: [PATCH] Implement -fsanitize=float-cast-overflow

2014-05-15 Thread Jakub Jelinek
On Wed, May 14, 2014 at 05:37:25PM +, Joseph S. Myers wrote: > > with s/max/min/;s/dconst1/dconstm1/; and, after the real_convert > > do inexact = real_arithmetic (&newminval, MINUS_EXPR, &minval, &dconst1); > > if !inexact just min = build_real (expr_type, newminval); and be done with > > it (

Re: [PATCH] Implement -fsanitize=float-cast-overflow

2014-05-14 Thread Joseph S. Myers
On Wed, 14 May 2014, Jakub Jelinek wrote: > So what do you see as the way to handle this properly? > I mean, for REAL_MODE_FORMAT (TYPE_MODE (expr_type))->b == 2 supposedly to > avoid issues with > rounding of the max we could just > REAL_VALUE_TYPE maxval = dconst1; > SET_REAL_EXP (&maxval,

Re: [PATCH] Implement -fsanitize=float-cast-overflow

2014-05-14 Thread Jakub Jelinek
On Tue, May 13, 2014 at 06:11:15PM +, Joseph S. Myers wrote: > > + tree min = TYPE_MIN_VALUE (type); > > + tree max = TYPE_MAX_VALUE (type); > > + /* Add/subtract 1.0 so we can avoid truncating the value of EXPR. */ > > + min = fold_build2 (MINUS_EXPR, expr_type, > > +build

Re: [PATCH] Implement -fsanitize=float-cast-overflow

2014-05-13 Thread Joseph S. Myers
On Tue, 13 May 2014, Marek Polacek wrote: > Here's an attempt to add the -fsanitize=float-cast-overflow > instrumentation. It should issue a runtime error when a floating-point > to integer type conversion overflows. Eventually it should instrument As with divide-by-zero, this should not be par

Re: [PATCH] Implement -fsanitize=float-cast-overflow

2014-05-13 Thread Jakub Jelinek
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

[PATCH] Implement -fsanitize=float-cast-overflow

2014-05-13 Thread Marek Polacek
Here's an attempt to add the -fsanitize=float-cast-overflow instrumentation. It should issue a runtime error when a floating-point to integer type conversion overflows. Eventually it should instrument even floating-point to floating-point conversions to detect e.g. (float)1e39 overflow, but I'd l