From 7176a4a096decd4a1930e4bd84f8ba2f05f13f81 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Mon, 2 May 2016 11:35:59 +0000 Subject: [PATCH] re PR c/70851 (internal compiler error: in create_tmp_var, at gimple-expr.c:473) PR c/70851 * c-decl.c (grokdeclarator): Diagnose when array's size has an incomplete type. * gcc.dg/enum-incomplete-3.c: New test. From-SVN: r235750 --- gcc/c/ChangeLog | 6 ++++++ gcc/c/c-decl.c | 15 +++++++++++++-- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/enum-incomplete-3.c | 20 ++++++++++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/enum-incomplete-3.c diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index f02fbdb3399..793186bfb63 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2016-05-02 Marek Polacek + + PR c/70851 + * c-decl.c (grokdeclarator): Diagnose when array's size has an + incomplete type. + 2016-04-29 Cesar Philippidis PR middle-end/70626 diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 16e4250194a..7094efc5dfe 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -5799,10 +5799,21 @@ grokdeclarator (const struct c_declarator *declarator, { if (name) error_at (loc, "size of array %qE has non-integer type", - name); + name); else error_at (loc, - "size of unnamed array has non-integer type"); + "size of unnamed array has non-integer type"); + size = integer_one_node; + } + /* This can happen with enum forward declaration. */ + else if (!COMPLETE_TYPE_P (TREE_TYPE (size))) + { + if (name) + error_at (loc, "size of array %qE has incomplete type", + name); + else + error_at (loc, "size of unnamed array has incomplete " + "type"); size = integer_one_node; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c4f45fa8b6c..3d6051cf884 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-05-02 Marek Polacek + + PR c/70851 + * gcc.dg/enum-incomplete-3.c: New test. + 2016-05-02 Marek Polacek Tom de Vries diff --git a/gcc/testsuite/gcc.dg/enum-incomplete-3.c b/gcc/testsuite/gcc.dg/enum-incomplete-3.c new file mode 100644 index 00000000000..db1138b56c6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/enum-incomplete-3.c @@ -0,0 +1,20 @@ +/* PR c/70851 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +enum E e; /* { dg-error "storage size" } */ + +void bar (int [e]); /* { dg-error "size of unnamed array has incomplete type" } */ +void bar2 (int [][e]); /* { dg-error "size of unnamed array has incomplete type" } */ + +void +foo (void) +{ + int a1[e]; /* { dg-error "size of array .a1. has incomplete type" } */ + int a2[e][3]; /* { dg-error "size of array .a2. has incomplete type" } */ + + struct S + { + int a3[e]; /* { dg-error "size of array .a3. has incomplete type" } */ + }; +} -- 2.30.2