From f406ae1fd66cbef7528139d813049d606973b4d2 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Fri, 17 Oct 2014 18:42:27 +0000 Subject: [PATCH] re PR c/63549 ([4.8/4.9/5] ICE in build_array_ref with invalid code) PR c/63549 * c-typeck.c (build_array_ref): Bail if the index in an incomplete type. * gcc.dg/pr63549.c: New test. From-SVN: r216413 --- gcc/c/ChangeLog | 6 ++++++ gcc/c/c-typeck.c | 2 ++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr63549.c | 7 +++++++ 4 files changed, 20 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr63549.c diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index d6a58a86e60..bb57ee22d41 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2014-10-17 Marek Polacek + + PR c/63549 + * c-typeck.c (build_array_ref): Bail if the index in an incomplete + type. + 2014-10-17 Marek Polacek * c-decl.c (grokdeclarator): Use OPT_Wimplicit_int unconditionally. diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 5c0697a9643..1e971c1b672 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -2478,6 +2478,8 @@ build_array_ref (location_t loc, tree array, tree index) /* Apply default promotions *after* noticing character types. */ index = default_conversion (index); + if (index == error_mark_node) + return error_mark_node; gcc_assert (TREE_CODE (TREE_TYPE (index)) == INTEGER_TYPE); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a73dad957c6..f9e3458477c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-10-17 Marek Polacek + + PR c/63549 + * gcc.dg/pr63549.c: New test. + 2014-10-17 Marek Polacek * gcc.dg/Wimplicit-int-1.c: New test. diff --git a/gcc/testsuite/gcc.dg/pr63549.c b/gcc/testsuite/gcc.dg/pr63549.c new file mode 100644 index 00000000000..c9b1718f0cc --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr63549.c @@ -0,0 +1,7 @@ +/* PR c/63549 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +enum E e; +int a[10]; +int i = a[e]; /* { dg-error "has an incomplete type" } */ -- 2.30.2