This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: reject decl with incomplete struct/union type in check_global_declaration()
- From: Joseph Myers <joseph at codesourcery dot com>
- To: Prathamesh Kulkarni <prathamesh dot kulkarni at linaro dot org>
- Cc: gcc Patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 15 Jan 2016 21:26:18 +0000
- Subject: Re: reject decl with incomplete struct/union type in check_global_declaration()
- Authentication-results: sourceware.org; auth=none
- References: <CAAgBjMmY0n=UaVTxXe+mPCSysYhPibsxOySihxt7TLH=ai3B1g at mail dot gmail dot com> <alpine dot DEB dot 2 dot 10 dot 1601142154520 dot 27845 at digraph dot polyomino dot org dot uk> <CAAgBjMmVYU1fcCVxZ+u15tXVxfO-Uk0gCNt7eZ=KwzdORHMcWA at mail dot gmail dot com>
On Fri, 15 Jan 2016, Prathamesh Kulkarni wrote:
> On 15 January 2016 at 03:27, Joseph Myers <joseph@codesourcery.com> wrote:
> > On Thu, 14 Jan 2016, Prathamesh Kulkarni wrote:
> >
> >> Hi,
> >> For test-case containing only the following declaration:
> >> static struct undefined_struct object;
> >> gcc rejects it at -O0 in assemble_variable() with error "storage size
> >> of <var> is unknown",
> >> however no error is reported when compiled with -O2.
> >
> > Cf bug 24293 (for the -fsyntax-only case) - does this patch fix that?
> Ah this doesn't fix PR24293, it seems analyze_function() doesn't get
> called for -fsyntax-only.
> I don't have a good solution for this. I assume varpool won't be
> populated for -fsyntax-only ?
> And we need to walk over decls with incomplete struct/union types
> after parsing the whole translation unit.
> In the attached patch, I kept a global vec<tree> incomplete_record_decls;
> In finish_decl(), if the decl is static, has type struct/union and
> size 0 then it is appened to incomplete_record_decls.
> In c_parser_translation_unit(), iterate over incomplete_record_decls
> and if report error if any decl has size zero.
> The patch passes testsuite.
There's a GNU C extension allowing forward declarations of enums, and it
seems that
static enum e x;
doesn't get diagnosed either with -fsyntax-only. Thus I think you should
cover that case as well.
--
Joseph S. Myers
joseph@codesourcery.com