Re: C, C++: New warning for memset without multiply by elt size

2016-05-15 Thread Gerald Pfeifer
For the record, this new warning/code found at least three actual bugs in Wine (two of which were in the testsuite, but still). Definitely a useful addition. Gerald

Re: C, C++: New warning for memset without multiply by elt size

2016-04-27 Thread Martin Sebor
On 04/27/2016 03:55 AM, Bernd Schmidt wrote: On 04/26/2016 11:23 PM, Martin Sebor wrote: The documentation for the new option implies that it should warn for calls to memset where the third argument contains the number of elements not multiplied by the element size. But in my (quick) testing

Re: C, C++: New warning for memset without multiply by elt size

2016-04-27 Thread Jeff Law
On 04/27/2016 03:55 AM, Bernd Schmidt wrote: On 04/26/2016 11:23 PM, Martin Sebor wrote: The documentation for the new option implies that it should warn for calls to memset where the third argument contains the number of elements not multiplied by the element size. But in my (quick) testing

Re: C, C++: New warning for memset without multiply by elt size

2016-04-27 Thread Bernd Schmidt
On 04/26/2016 11:23 PM, Martin Sebor wrote: The documentation for the new option implies that it should warn for calls to memset where the third argument contains the number of elements not multiplied by the element size. But in my (quick) testing it only warns when the argument is a constant

Re: C, C++: New warning for memset without multiply by elt size

2016-04-26 Thread Martin Sebor
On 04/25/2016 03:07 AM, Bernd Schmidt wrote: On 04/22/2016 03:57 PM, Jason Merrill wrote: This looks good, but can we move the code into c-common rather than duplicate it? That would be this patch. Also passes testing on x86_64-linux. Hi Bernd, I like the idea behind the patch! So much so

Re: C, C++: New warning for memset without multiply by elt size

2016-04-26 Thread Jason Merrill
On Tue, Apr 26, 2016 at 9:04 AM, Bernd Schmidt wrote: > On 04/25/2016 07:55 PM, Jason Merrill wrote: >> >> On 04/25/2016 05:07 AM, Bernd Schmidt wrote: >>> >>> +if (TREE_CODE (arg2) == CONST_DECL) >>> + arg2 = DECL_INITIAL (arg2); >>> +int

Re: C, C++: New warning for memset without multiply by elt size

2016-04-26 Thread Bernd Schmidt
On 04/25/2016 07:55 PM, Jason Merrill wrote: On 04/25/2016 05:07 AM, Bernd Schmidt wrote: +if (TREE_CODE (arg2) == CONST_DECL) + arg2 = DECL_INITIAL (arg2); +int literal_mask = ((!!integer_zerop (arg1) << 1) +| (!!integer_zerop (arg2) << 2)); Are

Re: C, C++: New warning for memset without multiply by elt size

2016-04-25 Thread Jason Merrill
On 04/25/2016 05:07 AM, Bernd Schmidt wrote: + if (TREE_CODE (arg2) == CONST_DECL) + arg2 = DECL_INITIAL (arg2); + int literal_mask = ((!!integer_zerop (arg1) << 1) + | (!!integer_zerop (arg2) << 2)); Are you

Re: C, C++: New warning for memset without multiply by elt size

2016-04-25 Thread Bernd Schmidt
On 04/22/2016 03:57 PM, Jason Merrill wrote: This looks good, but can we move the code into c-common rather than duplicate it? That would be this patch. Also passes testing on x86_64-linux. Bernd * doc/invoke.texi (Warning Options): Add -Wmemset-elt-size. (-Wmemset-elt-size): New item.

Re: C, C++: New warning for memset without multiply by elt size

2016-04-22 Thread Bernd Schmidt
On 04/22/2016 05:31 PM, Jason Merrill wrote: On Fri, Apr 22, 2016 at 11:24 AM, Bernd Schmidt wrote: On 04/22/2016 03:57 PM, Jason Merrill wrote: This looks good, but can we move the code into c-common rather than duplicate it? Probably not without a fair amount of

Re: C, C++: New warning for memset without multiply by elt size

2016-04-22 Thread Jason Merrill
On Fri, Apr 22, 2016 at 11:24 AM, Bernd Schmidt wrote: > On 04/22/2016 03:57 PM, Jason Merrill wrote: >> This looks good, but can we move the code into c-common rather than >> duplicate it? > > Probably not without a fair amount of surgery, since the cdw_ and ds_ codes >

Re: C, C++: New warning for memset without multiply by elt size

2016-04-22 Thread Bernd Schmidt
On 04/22/2016 03:57 PM, Jason Merrill wrote: This looks good, but can we move the code into c-common rather than duplicate it? Probably not without a fair amount of surgery, since the cdw_ and ds_ codes are private to each frontend. Bernd

Re: C, C++: New warning for memset without multiply by elt size

2016-04-22 Thread Jason Merrill
This looks good, but can we move the code into c-common rather than duplicate it? Jason On Fri, Apr 22, 2016 at 9:30 AM, Bernd Schmidt wrote: > We had this problem in the C frontend until very recently: > > int array[some_count]; > memset (array, 0, some_count); > >

C, C++: New warning for memset without multiply by elt size

2016-04-22 Thread Bernd Schmidt
We had this problem in the C frontend until very recently: int array[some_count]; memset (array, 0, some_count); which forgets to multiply by sizeof int. The following patch implements a new warning option for this. Bootstrapped and tested (a while ago, will retest) on x86_64-linux. Ok