re PR c/63549 ([4.8/4.9/5] ICE in build_array_ref with invalid code)
authorMarek Polacek <polacek@redhat.com>
Fri, 17 Oct 2014 18:42:27 +0000 (18:42 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 17 Oct 2014 18:42:27 +0000 (18:42 +0000)
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
gcc/c/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr63549.c [new file with mode: 0644]

index d6a58a86e60aac96615ee2e0a49f9a2706af2fe2..bb57ee22d41b0ed53903ecb4343ce398db7821a2 100644 (file)
@@ -1,3 +1,9 @@
+2014-10-17  Marek Polacek  <polacek@redhat.com>
+
+       PR c/63549
+       * c-typeck.c (build_array_ref): Bail if the index in an incomplete
+       type.
+
 2014-10-17  Marek Polacek  <polacek@redhat.com>
 
        * c-decl.c (grokdeclarator): Use OPT_Wimplicit_int unconditionally.
index 5c0697a9643379428bc32aa91c958901cf20ee5b..1e971c1b672d2978fbabae82f380392188731bd8 100644 (file)
@@ -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);
 
index a73dad957c653ebf6e370a30dda99711367dcaf4..f9e3458477c998bae1abcc81779bba33a0852992 100644 (file)
@@ -1,3 +1,8 @@
+2014-10-17  Marek Polacek  <polacek@redhat.com>
+
+       PR c/63549
+       * gcc.dg/pr63549.c: New test.
+
 2014-10-17  Marek Polacek  <polacek@redhat.com>
 
        * 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 (file)
index 0000000..c9b1718
--- /dev/null
@@ -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" } */