Re: [RFC] Detect most integer overflows.

2014-10-23 Thread Hannes Frederic Sowa
Hi Marek, On Do, 2014-10-23 at 10:23 +0200, Marek Polacek wrote: > On Tue, Apr 22, 2014 at 01:58:00PM +0200, Hannes Frederic Sowa wrote: > > I'll play around and will post a new patch in the not too distant > > future. ;) > > Are you still planning on posting the revised patch? Perhaps I could >

Re: [RFC] Detect most integer overflows.

2014-10-23 Thread Marek Polacek
Hi, On Tue, Apr 22, 2014 at 01:58:00PM +0200, Hannes Frederic Sowa wrote: > I'll play around and will post a new patch in the not too distant > future. ;) Are you still planning on posting the revised patch? Perhaps I could take and finish the patch, but I don't think I can do that because you d

Re: [RFC] Detect most integer overflows.

2014-04-22 Thread Hannes Frederic Sowa
On Thu, Apr 17, 2014 at 04:20:06PM +0200, Ondřej Bílka wrote: > On Sat, Apr 12, 2014 at 12:53:45AM +0200, Hannes Frederic Sowa wrote: > > Hi! > > > > On Tue, Oct 29, 2013 at 10:41:56AM +0100, Richard Biener wrote: > > > For a "quick" GCC implementation of the builtins you could expand > > > them t

Re: [RFC] Detect most integer overflows.

2014-04-22 Thread Hannes Frederic Sowa
On Tue, Apr 15, 2014 at 03:41:53PM +0200, Richard Biener wrote: > On Sat, Apr 12, 2014 at 12:53 AM, Hannes Frederic Sowa > wrote: > > Hi! > > > > On Tue, Oct 29, 2013 at 10:41:56AM +0100, Richard Biener wrote: > >> For a "quick" GCC implementation of the builtins you could expand > >> them to a op

Re: [RFC] Detect most integer overflows.

2014-04-17 Thread Ondřej Bílka
On Sat, Apr 12, 2014 at 12:53:45AM +0200, Hannes Frederic Sowa wrote: > Hi! > > On Tue, Oct 29, 2013 at 10:41:56AM +0100, Richard Biener wrote: > > For a "quick" GCC implementation of the builtins you could expand > > them to a open-coded sequence during gimplification. But due to > > the issues

Re: [RFC] Detect most integer overflows.

2014-04-15 Thread Richard Biener
On Sat, Apr 12, 2014 at 12:53 AM, Hannes Frederic Sowa wrote: > Hi! > > On Tue, Oct 29, 2013 at 10:41:56AM +0100, Richard Biener wrote: >> For a "quick" GCC implementation of the builtins you could expand >> them to a open-coded sequence during gimplification. But due to >> the issues pointed out

Re: [RFC] Detect most integer overflows.

2014-04-11 Thread Hannes Frederic Sowa
Hi! On Tue, Oct 29, 2013 at 10:41:56AM +0100, Richard Biener wrote: > For a "quick" GCC implementation of the builtins you could expand > them to a open-coded sequence during gimplification. But due to > the issues pointed out above I'm not sure it is the best interface > to support (though now t

Re: [RFC] Detect most integer overflows.

2013-11-27 Thread Ondřej Bílka
On Tue, Nov 26, 2013 at 12:31:00PM -0500, Geert Bosch wrote: > >> [...] > >> A few things helped to make the cost small: the biggest one is that > >> typically on of the operands is known to be negative or positive. > >> Gigi will use Ada type information, and Natural or Positive integer > >> var

Re: [RFC] Detect most integer overflows.

2013-11-26 Thread Geert Bosch
On Nov 9, 2013, at 02:48, Ondřej Bílka wrote: >> I've done the overflow checking in Gigi (Ada front end). Benchmarking >> real world large Ada programs (where every integer operation is checked, >> including array index computations etc.), I found the performance cost >> *very* small (less than

Re: [RFC] Detect most integer overflows.

2013-11-08 Thread Ondřej Bílka
On Fri, Nov 08, 2013 at 08:31:38PM -0500, Geert Bosch wrote: > > On Oct 29, 2013, at 05:41, Richard Biener wrote: > > > For reference those > > (http://clang.llvm.org/docs/LanguageExtensions.html) look like > > > > if (__builtin_umul_overflow(x, y, &result)) > >return kErrorCodeHackers; >

Re: [RFC] Detect most integer overflows.

2013-11-08 Thread Geert Bosch
On Oct 29, 2013, at 05:41, Richard Biener wrote: > For reference those > (http://clang.llvm.org/docs/LanguageExtensions.html) look like > > if (__builtin_umul_overflow(x, y, &result)) >return kErrorCodeHackers; > > which should be reasonably easy to support in GCC (if you factor out > gen

Re: [RFC] Detect most integer overflows.

2013-10-31 Thread David Brown
On 31/10/13 17:51, Andrew Haley wrote: On 10/31/2013 08:02 AM, David Brown wrote: On 30/10/13 16:56, Andrew Haley wrote: On 10/30/2013 03:23 PM, David Brown wrote: I believe that's only a minor reason for making signed overflows undefined behaviour. If it were a matter of implementation, I th

Re: [RFC] Detect most integer overflows.

2013-10-31 Thread Andrew Haley
On 10/31/2013 08:02 AM, David Brown wrote: > On 30/10/13 16:56, Andrew Haley wrote: >> On 10/30/2013 03:23 PM, David Brown wrote: >>> I believe that's only a minor reason for making signed overflows >>> undefined behaviour. If it were a matter of implementation, I think it >>> would have been made

Re: [RFC] Detect most integer overflows.

2013-10-31 Thread David Brown
On 30/10/13 16:56, Andrew Haley wrote: > On 10/30/2013 03:23 PM, David Brown wrote: >> I believe that's only a minor reason for making signed overflows >> undefined behaviour. If it were a matter of implementation, I think it >> would have been made "implementation defined" rather than "undefined"

Re: [RFC] Detect most integer overflows.

2013-10-30 Thread Andrew Haley
On 10/30/2013 03:23 PM, David Brown wrote: > I believe that's only a minor reason for making signed overflows > undefined behaviour. If it were a matter of implementation, I think it > would have been made "implementation defined" rather than "undefined", > so that two's complement machines could

Re: [RFC] Detect most integer overflows.

2013-10-30 Thread David Brown
On 30/10/13 15:59, Ondřej Bílka wrote: > On Wed, Oct 30, 2013 at 10:49:09AM -0400, Trevor Saunders wrote: >> On Wed, Oct 30, 2013 at 10:00:07AM +0100, Kai Tietz wrote: >>> 2013/10/30 Andrew Haley : On 10/30/2013 08:34 AM, Ondřej Bílka wrote: >> > The reasons of adding builtins is

Re: [RFC] Detect most integer overflows.

2013-10-30 Thread Trevor Saunders
On Wed, Oct 30, 2013 at 03:59:59PM +0100, Ondřej Bílka wrote: > On Wed, Oct 30, 2013 at 10:49:09AM -0400, Trevor Saunders wrote: > > On Wed, Oct 30, 2013 at 10:00:07AM +0100, Kai Tietz wrote: > > > 2013/10/30 Andrew Haley : > > > > On 10/30/2013 08:34 AM, Ondřej Bílka wrote: > > > > > > > >>> > > >

Re: [RFC] Detect most integer overflows.

2013-10-30 Thread Ondřej Bílka
On Wed, Oct 30, 2013 at 10:49:09AM -0400, Trevor Saunders wrote: > On Wed, Oct 30, 2013 at 10:00:07AM +0100, Kai Tietz wrote: > > 2013/10/30 Andrew Haley : > > > On 10/30/2013 08:34 AM, Ondřej Bílka wrote: > > > > > >>> > > >> The reasons of adding builtins is performance. Without that one can > >

Re: [RFC] Detect most integer overflows.

2013-10-30 Thread Trevor Saunders
On Wed, Oct 30, 2013 at 10:00:07AM +0100, Kai Tietz wrote: > 2013/10/30 Andrew Haley : > > On 10/30/2013 08:34 AM, Ondřej Bílka wrote: > > > >>> > >> The reasons of adding builtins is performance. Without that one can > >> write a simple template to generically check overflows like > >> > >> templa

Re: [RFC] Detect most integer overflows.

2013-10-30 Thread Florian Weimer
On 10/30/2013 03:03 PM, David Brown wrote: Technically speaking, casting your signed values to unsigned and using that to detect overflow will not necessarily work - I think it would be "implementation defined". But almost all architectures use two's compliment arithmetic, and it will work ther

Re: [RFC] Detect most integer overflows.

2013-10-30 Thread David Brown
On 30/10/13 10:00, Kai Tietz wrote: > 2013/10/30 Andrew Haley : >> On 10/30/2013 08:34 AM, Ondřej Bílka wrote: >> >>> The reasons of adding builtins is performance. Without that one can >>> write a simple template to generically check overflows like >>> >>> template class overflow { >>> pub

Re: [RFC] Detect most integer overflows.

2013-10-30 Thread Ondřej Bílka
On Wed, Oct 30, 2013 at 12:54:12PM +0100, Florian Weimer wrote: > On 10/26/2013 09:29 PM, Ondřej Bílka wrote: > >Hi, as I brainstormed how prevent possible overflows in memory allocation I > >came with heretic idea: > > > >For gcc -D_FORTIFY_SOURCE=2 we expand all multiplication with size_t > >type

Re: [RFC] Detect most integer overflows.

2013-10-30 Thread Florian Weimer
On 10/26/2013 09:29 PM, Ondřej Bílka wrote: Hi, as I brainstormed how prevent possible overflows in memory allocation I came with heretic idea: For gcc -D_FORTIFY_SOURCE=2 we expand all multiplication with size_t type by one that checks for integer overflow and aborts on it. This would prevent m

Re: [RFC] Detect most integer overflows.

2013-10-30 Thread Ondřej Bílka
On Wed, Oct 30, 2013 at 08:41:32AM +, Andrew Haley wrote: > On 10/30/2013 08:34 AM, Ondřej Bílka wrote: > > >> > > The reasons of adding builtins is performance. Without that one can > > write a simple template to generically check overflows like > > > > template class overflow { > > publi

Re: [RFC] Detect most integer overflows.

2013-10-30 Thread Kai Tietz
2013/10/30 Andrew Haley : > On 10/30/2013 08:34 AM, Ondřej Bílka wrote: > >>> >> The reasons of adding builtins is performance. Without that one can >> write a simple template to generically check overflows like >> >> template class overflow { >> public: >> C val; >> overflow operator + (ov

Re: [RFC] Detect most integer overflows.

2013-10-30 Thread Andrew Haley
On 10/30/2013 08:34 AM, Ondřej Bílka wrote: >> > The reasons of adding builtins is performance. Without that one can > write a simple template to generically check overflows like > > template class overflow { > public: > C val; > overflow operator + (overflow &y) { > overflow ret; >

Re: [RFC] Detect most integer overflows.

2013-10-30 Thread Ondřej Bílka
On Tue, Oct 29, 2013 at 10:41:56AM +0100, Richard Biener wrote: > On Sun, Oct 27, 2013 at 1:50 AM, Hannes Frederic Sowa > wrote: > > On Sat, Oct 26, 2013 at 09:29:12PM +0200, Ondřej Bílka wrote: > >> Hi, as I brainstormed how prevent possible overflows in memory allocation I > >> came with heretic

Re: [RFC] Detect most integer overflows.

2013-10-29 Thread Joseph S. Myers
On Tue, 29 Oct 2013, Richard Biener wrote: > LLVM covers addition, subtraction and multiply on signed and unsigned > int, long and long long types. Not sure why they offer anything for > unsigned - possibly for size_t arithmetic and security concerns with > malloc? For practicability and to be l

Re: [RFC] Detect most integer overflows.

2013-10-29 Thread Richard Biener
On Sun, Oct 27, 2013 at 1:50 AM, Hannes Frederic Sowa wrote: > On Sat, Oct 26, 2013 at 09:29:12PM +0200, Ondřej Bílka wrote: >> Hi, as I brainstormed how prevent possible overflows in memory allocation I >> came with heretic idea: >> >> For gcc -D_FORTIFY_SOURCE=2 we expand all multiplication with

Re: [RFC] Detect most integer overflows.

2013-10-27 Thread Ondřej Bílka
On Sun, Oct 27, 2013 at 02:15:57PM +0100, Jakub Jelinek wrote: > On Sun, Oct 27, 2013 at 12:35:24PM +0100, Ondřej Bílka wrote: > > On Sun, Oct 27, 2013 at 11:51:00AM +0100, Marek Polacek wrote: > > > Or just wait till the integer overflow detection in ubsan is completed. > > > > > As these computat

Re: [RFC] Detect most integer overflows.

2013-10-27 Thread Jakub Jelinek
On Sun, Oct 27, 2013 at 12:35:24PM +0100, Ondřej Bílka wrote: > On Sun, Oct 27, 2013 at 11:51:00AM +0100, Marek Polacek wrote: > > Or just wait till the integer overflow detection in ubsan is completed. > > > As these computations now are done on unsigned type which has behaviour > defined as modul

Re: [RFC] Detect most integer overflows.

2013-10-27 Thread Ondřej Bílka
On Sun, Oct 27, 2013 at 11:51:00AM +0100, Marek Polacek wrote: > Or just wait till the integer overflow detection in ubsan is completed. > As these computations now are done on unsigned type which has behaviour defined as modular arithmetic this would not help.

Re: [RFC] Detect most integer overflows.

2013-10-27 Thread Marek Polacek
Or just wait till the integer overflow detection in ubsan is completed. Marek

Re: [RFC] Detect most integer overflows.

2013-10-27 Thread Oleg Endo
On Sun, 2013-10-27 at 07:48 +0100, Ondřej Bílka wrote: > On Sun, Oct 27, 2013 at 01:50:14AM +0200, Hannes Frederic Sowa wrote: > > On Sat, Oct 26, 2013 at 09:29:12PM +0200, Ondřej Bílka wrote: > > > Hi, as I brainstormed how prevent possible overflows in memory allocation > > > I > > > came with h

Re: [RFC] Detect most integer overflows.

2013-10-26 Thread Ondřej Bílka
On Sun, Oct 27, 2013 at 01:50:14AM +0200, Hannes Frederic Sowa wrote: > On Sat, Oct 26, 2013 at 09:29:12PM +0200, Ondřej Bílka wrote: > > Hi, as I brainstormed how prevent possible overflows in memory allocation I > > came with heretic idea: > > > > For gcc -D_FORTIFY_SOURCE=2 we expand all multip

Re: [RFC] Detect most integer overflows.

2013-10-26 Thread Arnaud Charlet
>>> >>> >>> >> Or alternatively you could use the Ada language where integer overflow >> and buffer overflows are built into the language are fully handled by >> the compiler. >> > Yeah, I will suggest my boss in our project that cost $1 000 000 to > fire all C programmers, hire ada programmer

Re: [RFC] Detect most integer overflows.

2013-10-26 Thread Hannes Frederic Sowa
On Sat, Oct 26, 2013 at 09:29:12PM +0200, Ondřej Bílka wrote: > Hi, as I brainstormed how prevent possible overflows in memory allocation I > came with heretic idea: > > For gcc -D_FORTIFY_SOURCE=2 we expand all multiplication with size_t > type by one that checks for integer overflow and aborts o

Re: [RFC] Detect most integer overflows.

2013-10-26 Thread Ondřej Bílka
On Sat, Oct 26, 2013 at 09:41:36PM +0200, Arnaud Charlet wrote: > > Hi, as I brainstormed how prevent possible overflows in memory allocation I > > came with heretic idea: > > > > For gcc -D_FORTIFY_SOURCE=2 we expand all multiplication with size_t > > type by one that checks for integer overflow

Re: [RFC] Detect most integer overflows.

2013-10-26 Thread Arnaud Charlet
> Hi, as I brainstormed how prevent possible overflows in memory allocation I > came with heretic idea: > > For gcc -D_FORTIFY_SOURCE=2 we expand all multiplication with size_t > type by one that checks for integer overflow and aborts on it. This > would prevent most overflow at cost of breaking s

[RFC] Detect most integer overflows.

2013-10-26 Thread Ondřej Bílka
Hi, as I brainstormed how prevent possible overflows in memory allocation I came with heretic idea: For gcc -D_FORTIFY_SOURCE=2 we expand all multiplication with size_t type by one that checks for integer overflow and aborts on it. This would prevent most overflow at cost of breaking some legitima