]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-nested: Update assert for Fortran module vars [PR97927]
authorTobias Burnus <tobias@codesourcery.com>
Mon, 8 Mar 2021 12:05:48 +0000 (13:05 +0100)
committerTobias Burnus <tobias@codesourcery.com>
Mon, 15 Mar 2021 13:32:53 +0000 (14:32 +0100)
gcc/ChangeLog:

PR fortran/97927
* tree-nested.c (convert_local_reference_stmt): Avoid calling
lookup_field_for_decl for Fortran module (= namespace context).

gcc/testsuite/ChangeLog:

PR fortran/97927
* gfortran.dg/module_variable_3.f90: New test.

(cherry picked from commit 8a6a62614a8ae4544770420416d1632d6c3d3f6e)

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

diff --git a/gcc/testsuite/gfortran.dg/module_variable_3.f90 b/gcc/testsuite/gfortran.dg/module_variable_3.f90
new file mode 100644 (file)
index 0000000..0dae6d5
--- /dev/null
@@ -0,0 +1,37 @@
+! { dg-do compile }
+! { dg-additional-options "-fdump-tree-original" }
+!
+! PR fortran/97927
+!
+! Did ICE due to the in tree-nested.c due to {clobber}
+!
+
+module mpi2
+ interface
+   subroutine MPI_Allreduce(i)
+     implicit none
+     INTEGER, OPTIONAL, INTENT(OUT) :: i
+   end subroutine MPI_Allreduce
+ end interface
+end module
+
+module modmpi
+  implicit none
+  integer ierror  ! module variable = context NAMESPACE_DECL
+end module
+
+subroutine exxengy
+  use modmpi
+  use mpi2, only: mpi_allreduce
+  implicit none
+
+  ! intent(out) implies: ierror = {clobber}
+  call mpi_allreduce(ierror)
+
+contains
+  subroutine zrho2
+    return
+  end subroutine
+end subroutine
+
+! { dg-final { scan-tree-dump "ierror = {CLOBBER};" "original" } }
index fd2165b8bdb3a3d2b92024c6076319f0b708440e..0507d9afaf420ec44957e602bc29865eb3fb46ee 100644 (file)
@@ -2404,6 +2404,7 @@ convert_local_reference_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
        {
          tree lhs = gimple_assign_lhs (stmt);
          if (DECL_P (lhs)
+             && decl_function_context (lhs) == info->context
              && !use_pointer_in_frame (lhs)
              && lookup_field_for_decl (info, lhs, NO_INSERT))
            {