re PR fortran/71687 (ICE in omp_add_variable, at gimplify.c:5821)
authorJakub Jelinek <jakub@redhat.com>
Fri, 1 Jul 2016 20:52:54 +0000 (22:52 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 1 Jul 2016 20:52:54 +0000 (22:52 +0200)
PR fortran/71687
* f95-lang.c (struct binding_level): Add reversed field.
(clear_binding_level): Adjust initializer.
(getdecls): If reversed is clear, set it and nreverse the names
chain before returning it.
(poplevel): Use getdecls.
* trans-decl.c (gfc_generate_function_code, gfc_process_block_locals):
Use nreverse to pushdecl decls in the declaration order.

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

From-SVN: r237926

gcc/fortran/ChangeLog
gcc/fortran/f95-lang.c
gcc/fortran/trans-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/gomp/pr71687.f90 [new file with mode: 0644]

index 406a3822bde9f223f59d8ac3e3fdd1af8f69447d..9ecdc82e45511a13f9c183c8fac733f9d7d2ff61 100644 (file)
@@ -1,5 +1,14 @@
 2016-07-01  Jakub Jelinek  <jakub@redhat.com>
 
+       PR fortran/71687
+       * f95-lang.c (struct binding_level): Add reversed field.
+       (clear_binding_level): Adjust initializer.
+       (getdecls): If reversed is clear, set it and nreverse the names
+       chain before returning it.
+       (poplevel): Use getdecls.
+       * trans-decl.c (gfc_generate_function_code, gfc_process_block_locals):
+       Use nreverse to pushdecl decls in the declaration order.
+
        PR fortran/71717
        * trans-openmp.c (gfc_omp_privatize_by_reference): Return false
        for GFC_DECL_ASSOCIATE_VAR_P with POINTER_TYPE.
index 5849073b66e4148f78195a66f5e0dfb90484ef02..2b58173450a7f7407da6c6a584da651380133105 100644 (file)
@@ -286,6 +286,9 @@ binding_level {
   tree blocks;
   /* The binding level containing this one (the enclosing binding level).  */
   struct binding_level *level_chain;
+  /* True if nreverse has been already called on names; if false, names
+     are ordered from newest declaration to oldest one.  */
+  bool reversed;
 };
 
 /* The binding level currently in effect.  */
@@ -296,7 +299,7 @@ static GTY(()) struct binding_level *current_binding_level = NULL;
 static GTY(()) struct binding_level *global_binding_level;
 
 /* Binding level structures are initialized by copying this one.  */
-static struct binding_level clear_binding_level = { NULL, NULL, NULL };
+static struct binding_level clear_binding_level = { NULL, NULL, NULL, false };
 
 
 /* Return true if we are in the global binding level.  */
@@ -310,6 +313,11 @@ global_bindings_p (void)
 tree
 getdecls (void)
 {
+  if (!current_binding_level->reversed)
+    {
+      current_binding_level->reversed = true;
+      current_binding_level->names = nreverse (current_binding_level->names);
+    }
   return current_binding_level->names;
 }
 
@@ -347,7 +355,7 @@ poplevel (int keep, int functionbody)
      binding level that we are about to exit and which is returned by this
      routine.  */
   tree block_node = NULL_TREE;
-  tree decl_chain = current_binding_level->names;
+  tree decl_chain = getdecls ();
   tree subblock_chain = current_binding_level->blocks;
   tree subblock_node;
 
index 2f5e4342afaf6ff5d40e1841ad380e2138b91538..5626753c5d59f041db8b1beaab5a216ba961c448 100644 (file)
@@ -6277,7 +6277,7 @@ gfc_generate_function_code (gfc_namespace * ns)
                        gfc_finish_block (&cleanup));
 
   /* Add all the decls we created during processing.  */
-  decl = saved_function_decls;
+  decl = nreverse (saved_function_decls);
   while (decl)
     {
       tree next;
@@ -6469,7 +6469,7 @@ gfc_process_block_locals (gfc_namespace* ns)
   if (flag_coarray == GFC_FCOARRAY_LIB && has_coarray_vars)
     generate_coarray_init (ns);
 
-  decl = saved_local_decls;
+  decl = nreverse (saved_local_decls);
   while (decl)
     {
       tree next;
index 11af4b3b730e046ef2946e5ff1e4399a30eef058..08db9d19ed1d326d1f311128d61b12c3ca6ff85e 100644 (file)
@@ -1,3 +1,8 @@
+2016-07-01  Jakub Jelinek  <jakub@redhat.com>
+
+       PR fortran/71687
+       * gfortran.dg/gomp/pr71687.f90: New test.
+
 2016-07-01  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
 
        * gcc.dg/const-float128-ped.c: Require __float128 effective
diff --git a/gcc/testsuite/gfortran.dg/gomp/pr71687.f90 b/gcc/testsuite/gfortran.dg/gomp/pr71687.f90
new file mode 100644 (file)
index 0000000..3971263
--- /dev/null
@@ -0,0 +1,11 @@
+! PR fortran/71687
+! { dg-do compile }
+! { dg-additional-options "-fstack-arrays -O2" }
+
+subroutine s (n, x)
+   integer :: n
+   real :: x(n)
+!$omp parallel
+   x(1:n) = x(n:1:-1)
+!$omp end parallel
+end