]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR fortran/78298 (ICE in lookup_decl_in_outer_ctx, bei omp-low.c:4115)
authorJakub Jelinek <jakub@redhat.com>
Tue, 30 May 2017 07:45:47 +0000 (09:45 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 30 May 2017 07:45:47 +0000 (09:45 +0200)
Backported from mainline
2016-11-28  Jakub Jelinek  <jakub@redhat.com>

PR fortran/78298
* tree-nested.c (convert_local_reference_stmt): After adding
shared (FRAME.NN) clause to omp parallel, task or target,
add it also to all outer omp parallel, task or target constructs.

* gfortran.dg/gomp/pr78298.f90: New test.

From-SVN: r248629

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/gomp/pr78298.f90 [new file with mode: 0644]
gcc/tree-nested.c

index 256514d686f85c24d0d371fda77d78f11d65e7b7..43786fa65e23847a07ba0afc40e099635dd4a420 100644 (file)
@@ -1,6 +1,13 @@
 2017-05-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2016-11-28  Jakub Jelinek  <jakub@redhat.com>
+
+       PR fortran/78298
+       * tree-nested.c (convert_local_reference_stmt): After adding
+       shared (FRAME.NN) clause to omp parallel, task or target,
+       add it also to all outer omp parallel, task or target constructs.
+
        2016-11-23  Jakub Jelinek  <jakub@redhat.com>
 
        PR middle-end/69183
index ee5334cfe5eea1b25629dbd43dd4833e669ead32..780d457a30c293559ff0355a0b12c1e802dda071 100644 (file)
@@ -1,6 +1,11 @@
 2017-05-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2016-11-28  Jakub Jelinek  <jakub@redhat.com>
+
+       PR fortran/78298
+       * gfortran.dg/gomp/pr78298.f90: New test.
+
        2016-11-23  Jakub Jelinek  <jakub@redhat.com>
 
        PR middle-end/69183
diff --git a/gcc/testsuite/gfortran.dg/gomp/pr78298.f90 b/gcc/testsuite/gfortran.dg/gomp/pr78298.f90
new file mode 100644 (file)
index 0000000..85955c2
--- /dev/null
@@ -0,0 +1,28 @@
+! PR fortran/78298
+! { dg-do compile }
+! { dg-additional-options "-O2" }
+
+program pr78298
+  integer :: i, j, n
+  n = 2
+  !$omp parallel
+  !$omp do
+  do i = 1, n
+    !$omp parallel
+    !$omp do
+    do j = 1, n
+      call sub(i)
+    end do
+    !$omp end parallel
+  end do
+  !$omp end parallel
+  !call unused()
+contains
+  subroutine sub(x)
+    integer :: x
+  end
+  subroutine unused()
+    i = 0
+    j = 0
+  end
+end
index 4be86682d04c4d76f40b4dd7c04e57577c4208eb..e5af3597a54bb14e10c6a16289a4b7800fe7dc86 100644 (file)
@@ -1915,6 +1915,8 @@ convert_local_reference_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
   struct nesting_info *info = (struct nesting_info *) wi->info;
   tree save_local_var_chain;
   bitmap save_suppress;
+  char save_static_chain_added;
+  bool frame_decl_added;
   gimple stmt = gsi_stmt (*gsi);
 
   switch (gimple_code (stmt))
@@ -1922,29 +1924,44 @@ convert_local_reference_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
     case GIMPLE_OMP_PARALLEL:
     case GIMPLE_OMP_TASK:
       save_suppress = info->suppress_expansion;
+      frame_decl_added = false;
       if (convert_local_omp_clauses (gimple_omp_taskreg_clauses_ptr (stmt),
                                     wi))
        {
-         tree c;
+         tree c = build_omp_clause (gimple_location (stmt),
+                                    OMP_CLAUSE_SHARED);
          (void) get_frame_type (info);
-         c = build_omp_clause (gimple_location (stmt),
-                               OMP_CLAUSE_SHARED);
          OMP_CLAUSE_DECL (c) = info->frame_decl;
          OMP_CLAUSE_CHAIN (c) = gimple_omp_taskreg_clauses (stmt);
          gimple_omp_taskreg_set_clauses (stmt, c);
+         info->static_chain_added |= 4;
+         frame_decl_added = true;
        }
 
       save_local_var_chain = info->new_local_var_chain;
+      save_static_chain_added = info->static_chain_added;
       info->new_local_var_chain = NULL;
+      info->static_chain_added = 0;
 
       walk_body (convert_local_reference_stmt, convert_local_reference_op, info,
                 gimple_omp_body_ptr (stmt));
 
+      if ((info->static_chain_added & 4) != 0 && !frame_decl_added)
+       {
+         tree c = build_omp_clause (gimple_location (stmt),
+                                    OMP_CLAUSE_SHARED);
+         (void) get_frame_type (info);
+         OMP_CLAUSE_DECL (c) = info->frame_decl;
+         OMP_CLAUSE_CHAIN (c) = gimple_omp_taskreg_clauses (stmt);
+         info->static_chain_added |= 4;
+         gimple_omp_taskreg_set_clauses (stmt, c);
+       }
       if (info->new_local_var_chain)
        declare_vars (info->new_local_var_chain,
                      gimple_seq_first_stmt (gimple_omp_body (stmt)), false);
       info->new_local_var_chain = save_local_var_chain;
       info->suppress_expansion = save_suppress;
+      info->static_chain_added |= save_static_chain_added;
       break;
 
     case GIMPLE_OMP_FOR:
@@ -1985,29 +2002,46 @@ convert_local_reference_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
          break;
        }
       save_suppress = info->suppress_expansion;
+      frame_decl_added = false;
       if (convert_local_omp_clauses (gimple_omp_target_clauses_ptr (stmt), wi))
        {
-         tree c;
+         tree c = build_omp_clause (gimple_location (stmt), OMP_CLAUSE_MAP);
          (void) get_frame_type (info);
-         c = build_omp_clause (gimple_location (stmt), OMP_CLAUSE_MAP);
          OMP_CLAUSE_DECL (c) = info->frame_decl;
          OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TOFROM);
          OMP_CLAUSE_SIZE (c) = DECL_SIZE_UNIT (info->frame_decl);
          OMP_CLAUSE_CHAIN (c) = gimple_omp_target_clauses (stmt);
          gimple_omp_target_set_clauses (as_a <gomp_target *> (stmt), c);
+         info->static_chain_added |= 4;
+         frame_decl_added = true;
        }
 
       save_local_var_chain = info->new_local_var_chain;
+      save_static_chain_added = info->static_chain_added;
       info->new_local_var_chain = NULL;
+      info->static_chain_added = 0;
 
       walk_body (convert_local_reference_stmt, convert_local_reference_op, info,
                 gimple_omp_body_ptr (stmt));
 
+      if ((info->static_chain_added & 4) != 0 && !frame_decl_added)
+       {
+         tree c = build_omp_clause (gimple_location (stmt), OMP_CLAUSE_MAP);
+         (void) get_frame_type (info);
+         OMP_CLAUSE_DECL (c) = info->frame_decl;
+         OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TOFROM);
+         OMP_CLAUSE_SIZE (c) = DECL_SIZE_UNIT (info->frame_decl);
+         OMP_CLAUSE_CHAIN (c) = gimple_omp_target_clauses (stmt);
+         gimple_omp_target_set_clauses (as_a <gomp_target *> (stmt), c);
+         info->static_chain_added |= 4;
+       }
+
       if (info->new_local_var_chain)
        declare_vars (info->new_local_var_chain,
                      gimple_seq_first_stmt (gimple_omp_body (stmt)), false);
       info->new_local_var_chain = save_local_var_chain;
       info->suppress_expansion = save_suppress;
+      info->static_chain_added |= save_static_chain_added;
       break;
 
     case GIMPLE_OMP_TEAMS: