]> gcc.gnu.org Git - gcc.git/commitdiff
re PR middle-end/80853 (OpenMP ICE in build_outer_var_ref with array reduction)
authorJakub Jelinek <jakub@redhat.com>
Mon, 22 May 2017 18:51:54 +0000 (20:51 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 22 May 2017 18:51:54 +0000 (20:51 +0200)
PR middle-end/80853
* omp-low.c (lower_reduction_clauses): Pass OMP_CLAUSE_PRIVATE
as last argument to build_outer_var_ref for pointer bases of array
section reductions.

* testsuite/libgomp.c/pr80853.c: New test.

From-SVN: r248344

gcc/ChangeLog
gcc/omp-low.c
libgomp/ChangeLog
libgomp/testsuite/libgomp.c/pr80853.c [new file with mode: 0644]

index 3dac2253052f032b678be77a9e5626005595bcc0..b69ffc0d527e444683bd02a7fdde4b6939343abf 100644 (file)
@@ -1,3 +1,10 @@
+2017-05-22  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/80853
+       * omp-low.c (lower_reduction_clauses): Pass OMP_CLAUSE_PRIVATE
+       as last argument to build_outer_var_ref for pointer bases of array
+       section reductions.
+
 2017-05-19  Martin Sebor  <msebor@redhat.com>
 
        * print-tree.c (print_node): Print DECL_READ_P flag.
index 9cc29964dfa03c7f2eb4ba4043d11bc2216f1b15..26e6586a0706d362bca19825534e9cf598bae14b 100644 (file)
@@ -5140,15 +5140,25 @@ lower_reduction_clauses (tree clauses, gimple_seq *stmt_seqp, omp_context *ctx)
       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION)
        continue;
 
+      enum omp_clause_code ccode = OMP_CLAUSE_REDUCTION;
       orig_var = var = OMP_CLAUSE_DECL (c);
       if (TREE_CODE (var) == MEM_REF)
        {
          var = TREE_OPERAND (var, 0);
          if (TREE_CODE (var) == POINTER_PLUS_EXPR)
            var = TREE_OPERAND (var, 0);
-         if (TREE_CODE (var) == INDIRECT_REF
-             || TREE_CODE (var) == ADDR_EXPR)
+         if (TREE_CODE (var) == ADDR_EXPR)
            var = TREE_OPERAND (var, 0);
+         else
+           {
+             /* If this is a pointer or referenced based array
+                section, the var could be private in the outer
+                context e.g. on orphaned loop construct.  Pretend this
+                is private variable's outer reference.  */
+             ccode = OMP_CLAUSE_PRIVATE;
+             if (TREE_CODE (var) == INDIRECT_REF)
+               var = TREE_OPERAND (var, 0);
+           }
          orig_var = var;
          if (is_variable_sized (var))
            {
@@ -5162,7 +5172,7 @@ lower_reduction_clauses (tree clauses, gimple_seq *stmt_seqp, omp_context *ctx)
       new_var = lookup_decl (var, ctx);
       if (var == OMP_CLAUSE_DECL (c) && omp_is_reference (var))
        new_var = build_simple_mem_ref_loc (clause_loc, new_var);
-      ref = build_outer_var_ref (var, ctx);
+      ref = build_outer_var_ref (var, ctx, ccode);
       code = OMP_CLAUSE_REDUCTION_CODE (c);
 
       /* reduction(-:var) sums up the partial results, so it acts
index 460605b1b8aee24da41e4028268d0e0dbd9dd4ba..d49420aa90e06567eec90e27175fb504eaba2aa4 100644 (file)
@@ -1,3 +1,8 @@
+2017-05-22  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/80853
+       * testsuite/libgomp.c/pr80853.c: New test.
+
 2017-05-19  Thomas Schwinge  <thomas@codesourcery.com>
 
        * testsuite/libgomp.oacc-c++/template-reduction.C: Update.
diff --git a/libgomp/testsuite/libgomp.c/pr80853.c b/libgomp/testsuite/libgomp.c/pr80853.c
new file mode 100644 (file)
index 0000000..3c0ff10
--- /dev/null
@@ -0,0 +1,29 @@
+/* PR middle-end/80853 */
+/* { dg-do run } */
+
+__attribute__((noinline, noclone)) void
+foo (int *p)
+{
+  #pragma omp for reduction(+:p[:4])
+  for (int i = 0; i < 64; i++)
+    {
+      p[0] += i;
+      p[1] += i / 2;
+      p[2] += 2 * i;
+      p[3] += 3 * i;
+    }
+}
+
+int
+main ()
+{
+  int p[4] = { 0, 0, 0, 0 };
+  #pragma omp parallel
+  foo (p);
+  if (p[0] != 63 * 64 / 2
+      || p[1] != 31 * 32
+      || p[2] != 63 * 64
+      || p[3] != 3 * 63 * 64 / 2)
+    __builtin_abort ();
+  return 0;
+}
This page took 0.106004 seconds and 5 git commands to generate.