This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C/C++ PATCH] Reject declarators with huge arrays (PR c/68107, c++/68266)
- From: Marek Polacek <polacek at redhat dot com>
- To: Martin Sebor <msebor at gmail dot com>
- Cc: Joseph Myers <joseph at codesourcery dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>, Jason Merrill <jason at redhat dot com>, Martin Sebor <msebor at redhat dot com>
- Date: Wed, 11 Nov 2015 13:39:36 +0100
- Subject: Re: [C/C++ PATCH] Reject declarators with huge arrays (PR c/68107, c++/68266)
- Authentication-results: sourceware.org; auth=none
- References: <20151110163623 dot GB3185 at redhat dot com> <56424841 dot 9080800 at gmail dot com>
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 pointed out, any construction of a non-VLA type whose size is half or
> >more of the address space should receive a compile-time error.
> >
> >Done by moving up the check for the size in bytes so that it checks check every
> >non-VLA complete array type constructed in the course of processing the
> >declarator. Since the C++ FE had the same problem, I've fixed it up there as
> >well. And that's why I had to twek dg-error of two C++ tests; if the size of
> >an array is considered invalid, we give an error message with word "unnamed".
> >
> >(I've removed the comment about crashing in tree_to_[su]hwi since that seems
> >to no longer be the case.)
>
> Thanks for including me on this. I tested it with C++ references
> to arrays (in addition to pointers) and it works correctly for
> those as well (unsurprisingly). The only thing that bothers me
Good, thanks!
> a bit is that the seemingly arbitrary inconsistency between
> the diagnostics:
> >+ p = new char [1][MAX - 99]; // { dg-error "size of unnamed array" }
> > p = new char [1][MAX / 2]; // { dg-error "size of array" }
>
> Would it be possible to make the message issued by the front ends
> the same? I.e., either both "unnamed array" or both just "array?"
Yeah, I was thinking about that, too, but I was also hoping that we can
clean this up as a follow-up. I think let's drop the "unnamed" word, even
though that means that the changes in new44.C brought with my patch will
essentially have to be reverted...
Oh, and we could also be more informative and print the size of an array,
or the number of elements, as clang does.
Thanks,
Marek