This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH, Cilk+] Fix for PR62008


Hi!

Following patch adds necessary handling of the cases with incorrect type of an array in ArrayNotation and thus avoids ICE.

Regtested on x86_64.

Ok for trunk/4.9?

Thanks,
Igor

gcc/c/ChangeLog:

2014-08-07  Igor Zamyatin  <igor.zamyatin@intel.com>

      PR other/62008
      * c-parser.c (c_parser_array_notation): Check for correct
      type of an array added.
      
gcc/cp/ChangeLog:

2014-08-07  Igor Zamyatin  <igor.zamyatin@intel.com>

      PR other/62008
      * cp-array-notation.c (build_array_notation_ref): Added correct 
      handling of case with incorrect array. 

gcc/testsuite/ChangeLog:

2014-08-07  Igor Zamyatin  <igor.zamyatin@intel.com>

      PR other/62008
      * c-c++-common/cilk-plus/AN/pr62008.c: New test.



diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index e32bf04..d0e114a 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -14159,6 +14159,13 @@ c_parser_array_notation (location_t loc, c_parser *parser, tree initial_index,
---
   array_type = TREE_TYPE (array_value);
   gcc_assert (array_type);
+  if (TREE_CODE (array_type) != ARRAY_TYPE
+      && TREE_CODE (array_type) != POINTER_TYPE)
+    {
+      error_at (loc, "base of array section must be pointer or array type");
+      c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
+      return error_mark_node;
+    }
   type = TREE_TYPE (array_type);
   token = c_parser_peek_token (parser);
----
diff --git a/gcc/cp/cp-array-notation.c b/gcc/cp/cp-array-notation.c
index b45449b..e59c1f6 100644
--- a/gcc/cp/cp-array-notation.c
+++ b/gcc/cp/cp-array-notation.c
@@ -1393,7 +1393,10 @@ build_array_notation_ref (location_t loc, tree array, tree start, tree length,
   if (TREE_CODE (type) == ARRAY_TYPE || TREE_CODE (type) == POINTER_TYPE)
     TREE_TYPE (array_ntn_expr) = TREE_TYPE (type);
   else
-    gcc_unreachable ();
+    {
+      error_at (loc, "base of array section must be pointer or array type");
+      return error_mark_node;
+    }
-
   SET_EXPR_LOCATION (array_ntn_expr, loc);
   return array_ntn_expr;
diff --git a/gcc/testsuite/c-c++-common/cilk-plus/AN/pr62008.c b/gcc/testsuite/c-c++-common/cilk-plus/AN/pr62008.c
new file mode 100644
index 0000000..05734c5
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cilk-plus/AN/pr62008.c
@@ -0,0 +1,10 @@
+/* PR other/62008 */
+/* { dg-do compile } */
+/* { dg-options "-fcilkplus" } */
+
+void f(int *a, int w, int h)
+{
+  int tmp[w][h];
+  tmp[:][:] = a[0:w][0:h]; /* { dg-error "base of array section must be pointer or array type" } */
+  /* { dg-error "start-index and length fields necessary" "" { target c } 8 } */
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]