]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix PR c++/69363
authoriverbin <iverbin@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 20 Apr 2016 15:48:53 +0000 (15:48 +0000)
committeriverbin <iverbin@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 20 Apr 2016 15:48:53 +0000 (15:48 +0000)
gcc/c-family/
PR c++/69363
* c-cilkplus.c (c_finish_cilk_clauses): Remove function.
* c-common.h (c_finish_cilk_clauses): Remove declaration.
gcc/c/
PR c++/69363
* c-parser.c (c_parser_cilk_all_clauses): Use c_finish_omp_clauses
instead of c_finish_cilk_clauses.
* c-tree.h (c_finish_omp_clauses): Add new default argument.
* c-typeck.c (c_finish_omp_clauses): Add new argument.  Allow
floating-point variables in the linear clause for Cilk Plus.
gcc/cp/
PR c++/69363
* cp-tree.h (finish_omp_clauses): Add new default argument.
* parser.c (cp_parser_cilk_simd_all_clauses): Use finish_omp_clauses
instead of c_finish_cilk_clauses.
* semantics.c (finish_omp_clauses): Add new argument.  Allow
floating-point variables in the linear clause for Cilk Plus.
gcc/testsuite/
PR c++/69363
* c-c++-common/cilk-plus/PS/clauses3.c: Adjust dg-error string.
* c-c++-common/cilk-plus/PS/clauses4.c: New test.
* c-c++-common/cilk-plus/PS/pr69363.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@235290 138bc75d-0d04-0410-961f-82ee72b054a4

15 files changed:
gcc/c-family/ChangeLog
gcc/c-family/c-cilkplus.c
gcc/c-family/c-common.h
gcc/c/ChangeLog
gcc/c/c-parser.c
gcc/c/c-tree.h
gcc/c/c-typeck.c
gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/parser.c
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/cilk-plus/PS/clauses3.c
gcc/testsuite/c-c++-common/cilk-plus/PS/clauses4.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/cilk-plus/PS/pr69363.c [new file with mode: 0644]

index 7ae6903eb7e4aea5fa9266a6278570809b91340c..fc772147ae88a0b95c06e21e3133b044e27a3e0b 100644 (file)
@@ -1,3 +1,9 @@
+2016-04-20  Ilya Verbin  <ilya.verbin@intel.com>
+
+       PR c++/69363
+       * c-cilkplus.c (c_finish_cilk_clauses): Remove function.
+       * c-common.h (c_finish_cilk_clauses): Remove declaration.
+
 2016-04-18  Michael Matz  <matz@suse.de>
 
        * c-common.c (handle_aligned_attribute): Use SET_TYPE_ALIGN
index 3e7902fd11e6ccd94207f6f5bff60a003af5aef7..9f1f36471a8e0d5c6156bc0a986b03627fa290ec 100644 (file)
@@ -41,56 +41,6 @@ c_check_cilk_loop (location_t loc, tree decl)
   return true;
 }
 
-/* Validate and emit code for <#pragma simd> clauses.  */
-
-tree
-c_finish_cilk_clauses (tree clauses)
-{
-  for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
-    {
-      tree prev = clauses;
-
-      /* If a variable appears in a linear clause it cannot appear in
-        any other OMP clause.  */
-      if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR)
-       for (tree c2 = clauses; c2; c2 = OMP_CLAUSE_CHAIN (c2))
-         {
-           if (c == c2)
-             continue;
-           enum omp_clause_code code = OMP_CLAUSE_CODE (c2);
-
-           switch (code)
-             {
-             case OMP_CLAUSE_LINEAR:
-             case OMP_CLAUSE_PRIVATE:
-             case OMP_CLAUSE_FIRSTPRIVATE:
-             case OMP_CLAUSE_LASTPRIVATE:
-             case OMP_CLAUSE_REDUCTION:
-               break;
-
-             case OMP_CLAUSE_SAFELEN:
-               goto next;
-
-             default:
-               gcc_unreachable ();
-             }
-
-           if (OMP_CLAUSE_DECL (c) == OMP_CLAUSE_DECL (c2))
-             {
-               error_at (OMP_CLAUSE_LOCATION (c2),
-                         "variable appears in more than one clause");
-               inform (OMP_CLAUSE_LOCATION (c),
-                       "other clause defined here");
-               // Remove problematic clauses.
-               OMP_CLAUSE_CHAIN (prev) = OMP_CLAUSE_CHAIN (c2);
-             }
-         next:
-           prev = c2;
-         }
-    }
-  return clauses;
-}
-
 /* Calculate number of iterations of CILK_FOR.  */
 
 tree
index fa3746c3725034d083aa33506a71d189751ae8d1..663e457dd52b877c28bbb59a807d2a02b4f514f3 100644 (file)
@@ -1369,7 +1369,6 @@ extern enum stv_conv scalar_to_vector (location_t loc, enum tree_code code,
                                       tree op0, tree op1, bool);
 
 /* In c-cilkplus.c  */
-extern tree c_finish_cilk_clauses (tree);
 extern tree c_validate_cilk_plus_loop (tree *, int *, void *);
 extern bool c_check_cilk_loop (location_t, tree);
 
index b46df1f0a495e4a12be894539bff9044471327e8..e300200b0094e3268fdf517766b76d70c03c867f 100644 (file)
@@ -1,3 +1,12 @@
+2016-04-20  Ilya Verbin  <ilya.verbin@intel.com>
+
+       PR c++/69363
+       * c-parser.c (c_parser_cilk_all_clauses): Use c_finish_omp_clauses
+       instead of c_finish_cilk_clauses.
+       * c-tree.h (c_finish_omp_clauses): Add new default argument.
+       * c-typeck.c (c_finish_omp_clauses): Add new argument.  Allow
+       floating-point variables in the linear clause for Cilk Plus.
+
 2016-04-18  Michael Matz  <matz@suse.de>
 
        * c-decl.c (merge_decls): Use SET_DECL_ALIGN and SET_TYPE_ALIGN.
index 1b6bacd7498fb8ec37dc4b76bcfa26eacc1c8e1b..bdd669dec353ee6cde7625909e652719856ac52a 100644 (file)
@@ -17509,7 +17509,7 @@ c_parser_cilk_all_clauses (c_parser *parser)
 
  saw_error:
   c_parser_skip_to_pragma_eol (parser);
-  return c_finish_cilk_clauses (clauses);
+  return c_finish_omp_clauses (clauses, false, false, true);
 }
 
 /* This function helps parse the grainsize pragma for a _Cilk_for statement.
index d5592077524e4f64eb30e487c63400abb063d21e..4633182eef9301d3ef53aadc1b9128d7764baa68 100644 (file)
@@ -661,7 +661,7 @@ extern tree c_begin_omp_task (void);
 extern tree c_finish_omp_task (location_t, tree, tree);
 extern void c_finish_omp_cancel (location_t, tree);
 extern void c_finish_omp_cancellation_point (location_t, tree);
-extern tree c_finish_omp_clauses (tree, bool, bool = false);
+extern tree c_finish_omp_clauses (tree, bool, bool = false, bool = false);
 extern tree c_build_va_arg (location_t, tree, location_t, tree);
 extern tree c_finish_transaction (location_t, tree, int);
 extern bool c_tree_equal (tree, tree);
index 59a3c6153b7f3a4fe1a488d8c92a92dcca4171f3..58c21393e47eeee9e70f9fece638de060896b37e 100644 (file)
@@ -12496,7 +12496,8 @@ c_find_omp_placeholder_r (tree *tp, int *, void *data)
    Remove any elements from the list that are invalid.  */
 
 tree
-c_finish_omp_clauses (tree clauses, bool is_omp, bool declare_simd)
+c_finish_omp_clauses (tree clauses, bool is_omp, bool declare_simd,
+                     bool is_cilk)
 {
   bitmap_head generic_head, firstprivate_head, lastprivate_head;
   bitmap_head aligned_head, map_head, map_field_head;
@@ -12778,14 +12779,31 @@ c_finish_omp_clauses (tree clauses, bool is_omp, bool declare_simd)
                        "clause on %<simd%> or %<for%> constructs");
              OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
            }
-         if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
-             && TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE)
+         if (is_cilk)
            {
-             error_at (OMP_CLAUSE_LOCATION (c),
-                       "linear clause applied to non-integral non-pointer "
-                       "variable with type %qT", TREE_TYPE (t));
-             remove = true;
-             break;
+             if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
+                 && !SCALAR_FLOAT_TYPE_P (TREE_TYPE (t))
+                 && TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE)
+               {
+                 error_at (OMP_CLAUSE_LOCATION (c),
+                           "linear clause applied to non-integral, "
+                           "non-floating, non-pointer variable with type %qT",
+                           TREE_TYPE (t));
+                 remove = true;
+                 break;
+               }
+           }
+         else
+           {
+             if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
+                 && TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE)
+               {
+                 error_at (OMP_CLAUSE_LOCATION (c),
+                           "linear clause applied to non-integral non-pointer "
+                           "variable with type %qT", TREE_TYPE (t));
+                 remove = true;
+                 break;
+               }
            }
          if (declare_simd)
            {
index 008bc355b03b2fcdc752a1e9b96f3f698799e5cb..7cccddb3e4461ca016c733c9dc7c2f1dafdbca3f 100644 (file)
@@ -1,3 +1,12 @@
+2016-04-20  Ilya Verbin  <ilya.verbin@intel.com>
+
+       PR c++/69363
+       * cp-tree.h (finish_omp_clauses): Add new default argument.
+       * parser.c (cp_parser_cilk_simd_all_clauses): Use finish_omp_clauses
+       instead of c_finish_cilk_clauses.
+       * semantics.c (finish_omp_clauses): Add new argument.  Allow
+       floating-point variables in the linear clause for Cilk Plus.
+
 2016-04-20  Nathan Sidwell  <nathan@acm.org>
 
        * semantics.c (finish_compound_lteral): Don't wrap VECTOR_TYPEs in a
index 0df84707f8811a220e6d64caeaf7e4c13090e355..ec92718626c22d52670b0013307b92acbc02609d 100644 (file)
@@ -6396,7 +6396,8 @@ extern tree omp_reduction_id                      (enum tree_code, tree, tree);
 extern tree cp_remove_omp_priv_cleanup_stmt    (tree *, int *, void *);
 extern void cp_check_omp_declare_reduction     (tree);
 extern void finish_omp_declare_simd_methods    (tree);
-extern tree finish_omp_clauses                 (tree, bool, bool = false);
+extern tree finish_omp_clauses                 (tree, bool, bool = false,
+                                                bool = false);
 extern tree push_omp_privatization_clauses     (bool);
 extern void pop_omp_privatization_clauses      (tree);
 extern void save_omp_privatization_clauses     (vec<tree> &);
index 54861298c84a0240aa1e3d8e4b5ae9edb8e7ed87..0a1ed1a971053ff354ea0205678521e45615876a 100644 (file)
@@ -37714,7 +37714,7 @@ cp_parser_cilk_simd_all_clauses (cp_parser *parser, cp_token *pragma_token)
   if (clauses == error_mark_node)
     return error_mark_node;
   else
-    return c_finish_cilk_clauses (clauses);
+    return finish_omp_clauses (clauses, false, false, true);
 }
 
 /* Main entry-point for parsing Cilk Plus <#pragma simd> for loops.  */
index 1dff08e29d912690c3c95b5a309e4a219b144874..93b39ac9a77a84a2cba86103d79172960536d377 100644 (file)
@@ -5793,7 +5793,8 @@ cp_finish_omp_clause_depend_sink (tree sink_clause)
    Remove any elements from the list that are invalid.  */
 
 tree
-finish_omp_clauses (tree clauses, bool allow_fields, bool declare_simd)
+finish_omp_clauses (tree clauses, bool allow_fields, bool declare_simd,
+                   bool is_cilk)
 {
   bitmap_head generic_head, firstprivate_head, lastprivate_head;
   bitmap_head aligned_head, map_head, map_field_head;
@@ -5889,13 +5890,29 @@ finish_omp_clauses (tree clauses, bool allow_fields, bool declare_simd)
                }
              if (TREE_CODE (type) == REFERENCE_TYPE)
                type = TREE_TYPE (type);
-             if (!INTEGRAL_TYPE_P (type)
-                 && TREE_CODE (type) != POINTER_TYPE)
+             if (is_cilk)
                {
-                 error ("linear clause applied to non-integral non-pointer "
-                        "variable with %qT type", TREE_TYPE (t));
-                 remove = true;
-                 break;
+                 if (!INTEGRAL_TYPE_P (type)
+                     && !SCALAR_FLOAT_TYPE_P (type)
+                     && TREE_CODE (type) != POINTER_TYPE)
+                   {
+                     error ("linear clause applied to non-integral, "
+                            "non-floating, non-pointer variable with %qT type",
+                            TREE_TYPE (t));
+                     remove = true;
+                     break;
+                   }
+               }
+             else
+               {
+                 if (!INTEGRAL_TYPE_P (type)
+                     && TREE_CODE (type) != POINTER_TYPE)
+                   {
+                     error ("linear clause applied to non-integral non-pointer"
+                            " variable with %qT type", TREE_TYPE (t));
+                     remove = true;
+                     break;
+                   }
                }
            }
          t = OMP_CLAUSE_LINEAR_STEP (c);
index 50d37d21ff060fe5a6f73bb1bc4e25e1807f69d6..bf59b9b180271e7c5288f7bacf7e56c3996c1c86 100644 (file)
@@ -1,3 +1,10 @@
+2016-04-20  Ilya Verbin  <ilya.verbin@intel.com>
+
+       PR c++/69363
+       * c-c++-common/cilk-plus/PS/clauses3.c: Adjust dg-error string.
+       * c-c++-common/cilk-plus/PS/clauses4.c: New test.
+       * c-c++-common/cilk-plus/PS/pr69363.c: New test.
+
 2016-04-20  Bin Cheng  <bin.cheng@arm.com>
 
        PR tree-optimization/56625
index 579b718a01c6932bda162ecfb57cf666b6026edc..0b5ace6a1a091fee6e5d2dbfade33471e2e03b87 100644 (file)
@@ -6,31 +6,31 @@
 int A[N], B[N], C[N];
 int main (void)
 {
-#pragma simd private (B) linear(B:1) /* { dg-error "more than one clause" } */
+#pragma simd private (B) linear(B:1) /* { dg-error "applied to non-integral" } */
   for (int ii = 0; ii < N; ii++)
     {
       A[ii] = B[ii] + C[ii];
     }
 
-#pragma simd private (B, C) linear(B:1) /* { dg-error "more than one clause" } */
+#pragma simd private (B, C) linear(B:1) /* { dg-error "applied to non-integral" } */
   for (int ii = 0; ii < N; ii++)
     {
       A[ii] = B[ii] + C[ii];
     }
 
-#pragma simd private (B) linear(C:2, B:1) /* { dg-error "more than one clause" } */
+#pragma simd private (B) linear(C:2, B:1) /* { dg-error "applied to non-integral" } */
   for (int ii = 0; ii < N; ii++)
     {
       A[ii] = B[ii] + C[ii];
     }
 
-#pragma simd reduction (+:B) linear(B:1) /* { dg-error "more than one clause" } */
+#pragma simd reduction (+:B) linear(B:1) /* { dg-error "applied to non-integral" } */
   for (int ii = 0; ii < N; ii++)
     {
       A[ii] = B[ii] + C[ii];
     }
 
-#pragma simd reduction (+:B) linear(B) /* { dg-error "more than one clause" } */
+#pragma simd reduction (+:B) linear(B) /* { dg-error "applied to non-integral" } */
   for (int ii = 0; ii < N; ii++)
     {
       A[ii] = B[ii] + C[ii];
diff --git a/gcc/testsuite/c-c++-common/cilk-plus/PS/clauses4.c b/gcc/testsuite/c-c++-common/cilk-plus/PS/clauses4.c
new file mode 100644 (file)
index 0000000..45dcb9f
--- /dev/null
@@ -0,0 +1,36 @@
+/* { dg-do compile } */
+/* { dg-options "-fcilkplus" } */
+
+#define N 1000
+
+int B, C;
+double D;
+
+int main (void)
+{
+  #pragma simd linear (D:10)
+  for (int ii = 0; ii < N; ii++)
+    ;
+
+  #pragma simd private (B) linear(B:1) /* { dg-error "more than once" } */
+  for (int ii = 0; ii < N; ii++)
+    ;
+
+  #pragma simd private (B, C) linear(B:1) /* { dg-error "more than once" } */
+  for (int ii = 0; ii < N; ii++)
+    ;
+
+  #pragma simd private (B) linear(C:2, B:1) /* { dg-error "more than once" } */
+  for (int ii = 0; ii < N; ii++)
+    ;
+
+  #pragma simd reduction (+:B) linear(B:1) /* { dg-error "more than once" } */
+  for (int ii = 0; ii < N; ii++)
+    ;
+
+  #pragma simd reduction (+:B) linear(B) /* { dg-error "more than once" } */
+  for (int ii = 0; ii < N; ii++)
+    ;
+
+  return 0;
+}
diff --git a/gcc/testsuite/c-c++-common/cilk-plus/PS/pr69363.c b/gcc/testsuite/c-c++-common/cilk-plus/PS/pr69363.c
new file mode 100644 (file)
index 0000000..1d1bb04
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-fcilkplus" } */
+
+double t1 (double *x, int N)
+{
+  double result = 0.0;
+
+  #pragma simd reduction (max: result)
+  for (int i = 0; i < N; ++i)
+    result = x[i] > result ? x[i] : result;
+
+  return result;
+}