Re: [C/C++ PATCH] Reject declarators with huge arrays (PR c/68107, c++/68266)

2015-11-11 Thread Marek Polacek
On Tue, Nov 10, 2015 at 12:40:49PM -0700, Martin Sebor wrote: > On 11/10/2015 09:36 AM, Marek Polacek wrote: > >While both C and C++ FEs are able to reject e.g. > >int a[__SIZE_MAX__ / sizeof(int)]; > >they are accepting code such as > >int (*a)[__SIZE_MAX__ / sizeof(int)]; > > > >As Joseph

Re: [C/C++ PATCH] Reject declarators with huge arrays (PR c/68107, c++/68266)

2015-11-11 Thread Marek Polacek
On Tue, Nov 10, 2015 at 04:48:13PM -0700, Jeff Law wrote: > Someone (I can't recall who) suggested the overflow check ought to be > shared, I agree. Can you factor out that check, shove it into c-family/ and > call it from the C & C++ front-ends? > > Approved with that change. Please post it

Re: [C/C++ PATCH] Reject declarators with huge arrays (PR c/68107, c++/68266)

2015-11-11 Thread Marek Polacek
On Tue, Nov 10, 2015 at 06:38:31PM +0100, Paolo Carlini wrote: > Hi, > > On 11/10/2015 05:36 PM, Marek Polacek wrote: > >+ > >+/* Did array size calculations overflow or does the array > >+ cover more than half of the address-space? */ > >+if

Re: [C/C++ PATCH] Reject declarators with huge arrays (PR c/68107, c++/68266)

2015-11-11 Thread Marek Polacek
On Wed, Nov 11, 2015 at 01:42:04PM +0100, Bernd Schmidt wrote: > On 11/11/2015 01:31 PM, Marek Polacek wrote: > > >Certainly I'm in favor of sharing code between C and C++ FEs, though in > >this case it didn't seem too important/obvious, because of the extra != > >error_mark_node check + I don't

Re: [C/C++ PATCH] Reject declarators with huge arrays (PR c/68107, c++/68266)

2015-11-11 Thread Bernd Schmidt
On 11/11/2015 01:31 PM, Marek Polacek wrote: Certainly I'm in favor of sharing code between C and C++ FEs, though in this case it didn't seem too important/obvious, because of the extra != error_mark_node check + I don't really like the new function getting *type and setting it there. Make it

Re: [C/C++ PATCH] Reject declarators with huge arrays (PR c/68107, c++/68266)

2015-11-11 Thread Martin Sebor
Oh, and we could also be more informative and print the size of an array, or the number of elements, as clang does. Yes, that's pretty nice. It helps but the diagnostic must point at the right dimension. GCC often just points at the whole expression or some token within it. void* foo () {

Re: [C/C++ PATCH] Reject declarators with huge arrays (PR c/68107, c++/68266)

2015-11-10 Thread Joseph Myers
On Tue, 10 Nov 2015, Marek Polacek wrote: > While both C and C++ FEs are able to reject e.g. > int a[__SIZE_MAX__ / sizeof(int)]; > they are accepting code such as > int (*a)[__SIZE_MAX__ / sizeof(int)]; > > As Joseph pointed out, any construction of a non-VLA type whose size is half > or >

Re: [C/C++ PATCH] Reject declarators with huge arrays (PR c/68107, c++/68266)

2015-11-10 Thread Paolo Carlini
Hi, On 11/10/2015 05:36 PM, Marek Polacek wrote: + + /* Did array size calculations overflow or does the array + cover more than half of the address-space? */ + if (COMPLETE_TYPE_P (type) + && TREE_CODE (TYPE_SIZE_UNIT (type)) ==

Re: [C/C++ PATCH] Reject declarators with huge arrays (PR c/68107, c++/68266)

2015-11-10 Thread Martin Sebor
On 11/10/2015 09:36 AM, Marek Polacek wrote: While both C and C++ FEs are able to reject e.g. int a[__SIZE_MAX__ / sizeof(int)]; they are accepting code such as int (*a)[__SIZE_MAX__ / sizeof(int)]; As Joseph pointed out, any construction of a non-VLA type whose size is half or more of the

Re: [C/C++ PATCH] Reject declarators with huge arrays (PR c/68107, c++/68266)

2015-11-10 Thread Jeff Law
On 11/10/2015 09:36 AM, Marek Polacek wrote: While both C and C++ FEs are able to reject e.g. int a[__SIZE_MAX__ / sizeof(int)]; they are accepting code such as int (*a)[__SIZE_MAX__ / sizeof(int)]; As Joseph pointed out, any construction of a non-VLA type whose size is half or more of the