]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c-parser.c (c_finish_taskloop_clauses): New function.
authorJakub Jelinek <jakub@redhat.com>
Wed, 17 Oct 2018 10:49:14 +0000 (12:49 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 17 Oct 2018 10:49:14 +0000 (12:49 +0200)
* c-parser.c (c_finish_taskloop_clauses): New function.
(c_parser_omp_taskloop): Use it.
* c-typeck.c (c_finish_omp_clauses): Call save_expr for whole array
reduction sizes.  Diagnose reductions with zero sized elements or
variable length structures.

* semantics.c (finish_omp_reduction_clause): Call save_expr for
whole array reduction sizes.

* gcc.dg/gomp/reduction-2.c: New test.

From-SVN: r265236

gcc/c/ChangeLog.gomp
gcc/c/c-parser.c
gcc/c/c-typeck.c
gcc/cp/ChangeLog.gomp
gcc/cp/semantics.c
gcc/testsuite/ChangeLog.gomp
gcc/testsuite/gcc.dg/gomp/reduction-2.c [new file with mode: 0644]

index d759f0d8a78ebf1e7056e0a6bcb0d76084cd53bf..e4fcbc43c571660bb866757974a43f0bfcbda232 100644 (file)
@@ -1,3 +1,11 @@
+2018-10-17  Jakub Jelinek  <jakub@redhat.com>
+
+       * c-parser.c (c_finish_taskloop_clauses): New function.
+       (c_parser_omp_taskloop): Use it.
+       * c-typeck.c (c_finish_omp_clauses): Call save_expr for whole array
+       reduction sizes.  Diagnose reductions with zero sized elements or
+       variable length structures.
+
 2018-10-16  Jakub Jelinek  <jakub@redhat.com>
 
        * c-typeck.c (handle_omp_array_sections): Call save_expr on array
index 8c3e2568b515f2a99832ebb49ecc5220288a4772..84036a9c049ed67ebd3664c5820d829703a3abe7 100644 (file)
@@ -18823,6 +18823,41 @@ c_parser_omp_requires (c_parser *parser)
     error_at (loc, "%<pragma omp requires%> requires at least one clause");
 }
 
+/* Helper function for c_parser_omp_taskloop.
+   Disallow zero sized or potentially zero sized task reductions.  */
+
+static tree
+c_finish_taskloop_clauses (tree clauses)
+{
+  tree *pc = &clauses;
+  for (tree c = clauses; c; c = *pc)
+    {
+      bool remove = false;
+      if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
+       {
+         tree type = strip_array_types (TREE_TYPE (OMP_CLAUSE_DECL (c)));
+         if (integer_zerop (TYPE_SIZE_UNIT (type)))
+           {
+             error_at (OMP_CLAUSE_LOCATION (c),
+                       "zero sized type %qT in %<reduction%> clause", type);
+             remove = true;
+           }
+         else if (TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST)
+           {
+             error_at (OMP_CLAUSE_LOCATION (c),
+                       "variable sized type %qT in %<reduction%> clause",
+                       type);
+             remove = true;
+           }
+       }
+      if (remove)
+       *pc = OMP_CLAUSE_CHAIN (c);
+      else
+       pc = &OMP_CLAUSE_CHAIN (c);
+    }
+  return clauses;
+}
+
 /* OpenMP 4.5:
    #pragma omp taskloop taskloop-clause[optseq] new-line
      for-loop
@@ -18880,6 +18915,8 @@ c_parser_omp_taskloop (location_t loc, c_parser *parser,
          TREE_TYPE (ret) = void_type_node;
          OMP_FOR_BODY (ret) = block;
          OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP];
+         OMP_FOR_CLAUSES (ret)
+           = c_finish_taskloop_clauses (OMP_FOR_CLAUSES (ret));
          SET_EXPR_LOCATION (ret, loc);
          add_stmt (ret);
          return ret;
@@ -18898,6 +18935,7 @@ c_parser_omp_taskloop (location_t loc, c_parser *parser,
       clauses = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP];
     }
 
+  clauses = c_finish_taskloop_clauses (clauses);
   block = c_begin_compound_stmt (true);
   ret = c_parser_omp_for_loop (loc, parser, OMP_TASKLOOP, clauses, NULL, if_p);
   block = c_end_compound_stmt (loc, block, true);
index 9f03ff7defdf6ff0601b524835b3eab274114e4a..70ec23baadd7b5eb5fa7be637aed3cc843e29c36 100644 (file)
@@ -13343,6 +13343,7 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
                  break;
                }
              size = size_binop (MINUS_EXPR, size, size_one_node);
+             size = save_expr (size);
              tree index_type = build_index_type (size);
              tree atype = build_array_type (type, index_type);
              tree ptype = build_pointer_type (type);
@@ -13358,6 +13359,28 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
              remove = true;
              break;
            }
+         if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
+             || OMP_CLAUSE_REDUCTION_TASK (c))
+           {
+             /* Disallow zero sized or potentially zero sized task
+                reductions.  */
+             if (integer_zerop (TYPE_SIZE_UNIT (type)))
+               {
+                 error_at (OMP_CLAUSE_LOCATION (c),
+                           "zero sized type %qT in %qs clause", type,
+                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+                 remove = true;
+                 break;
+               }
+             else if (TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST)
+               {
+                 error_at (OMP_CLAUSE_LOCATION (c),
+                           "variable sized type %qT in %qs clause", type,
+                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+                 remove = true;
+                 break;
+               }
+           }
          if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == NULL_TREE
              && (FLOAT_TYPE_P (type)
                  || TREE_CODE (type) == COMPLEX_TYPE))
index 88c01445757a5179bc9510570edda7b73d843320..7d853b9f9d2a54d50c39ec6208317b6ddaec721b 100644 (file)
@@ -1,3 +1,8 @@
+2018-10-17  Jakub Jelinek  <jakub@redhat.com>
+
+       * semantics.c (finish_omp_reduction_clause): Call save_expr for
+       whole array reduction sizes.
+
 2018-10-16  Jakub Jelinek  <jakub@redhat.com>
 
        * pt.c (tsubst_omp_clauses): Handle OMP_CLAUSE_IN_REDUCTION and
index 23d4e51ed04277ea2c981f40e8b3527cd540f7aa..894fec13cf09a2c6c168753c4c49f958423e781c 100644 (file)
@@ -5567,6 +5567,7 @@ finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor)
              return true;
            }
          size = size_binop (MINUS_EXPR, size, size_one_node);
+         size = save_expr (size);
          tree index_type = build_index_type (size);
          tree atype = build_array_type (type, index_type);
          tree ptype = build_pointer_type (type);
index 6e143f3118c1856c1943164a67569dea88a24519..d134e31b3d2a10ab5176b30f35b1a26d2ebccd7e 100644 (file)
@@ -1,3 +1,7 @@
+2018-10-17  Jakub Jelinek  <jakub@redhat.com>
+
+       * gcc.dg/gomp/reduction-2.c: New test.
+
 2018-10-16  Jakub Jelinek  <jakub@redhat.com>
 
        * c-c++-common/gomp/clauses-1.c (r2): New variable.
diff --git a/gcc/testsuite/gcc.dg/gomp/reduction-2.c b/gcc/testsuite/gcc.dg/gomp/reduction-2.c
new file mode 100644 (file)
index 0000000..f8ac8b6
--- /dev/null
@@ -0,0 +1,30 @@
+/* { dg-do compile } */
+/* { dg-options "-fopenmp" } */
+
+struct S {};
+void foo (void *, void *);
+void bar (void *, void *);
+void baz (void *);
+#pragma omp declare reduction(+:struct S:foo (&omp_out, &omp_in))initializer(bar(&omp_priv, &omp_orig))
+
+void
+test1 (void)
+{
+  struct S s;
+  int i;
+  #pragma omp parallel reduction(+:s)
+    baz (&s);
+  #pragma omp parallel reduction(task, +:s)    /* { dg-error "zero sized type 'struct S' in 'reduction' clause" } */
+    baz (&s);
+  #pragma omp taskloop reduction(+:s)          /* { dg-error "zero sized type 'struct S' in 'reduction' clause" } */
+  for (i = 0; i < 1; i++)
+    baz (&s);
+  #pragma omp taskloop simd reduction(+:s)     /* { dg-error "zero sized type 'struct S' in 'reduction' clause" } */
+  for (i = 0; i < 1; i++)
+    baz (&s);
+  #pragma omp taskgroup task_reduction(+:s)    /* { dg-error "zero sized type 'struct S' in 'task_reduction' clause" } */
+  {
+    #pragma omp task in_reduction(+:s)         /* { dg-error "zero sized type 'struct S' in 'in_reduction' clause" } */
+    baz (&s);
+  }
+}