Hi!

As mentioned in the PR, the following testcases FAIL, because a VAR_DECL
for a PARAMETER inside of a BLOCK is not added to the BIND_EXPR vars and
thus the middle-end doesn't consider it defined.

The problem is in the following test, which passes for all the PR67885
tests, but doesn't really test whether this is a parameter in a BLOCK
namespace.  It actually tests whether the parent namespace (usually
function/subroutine body, but could be another BLOCK) has EXEC_BLOCK as
the first executable statement in it.
As I said in the PR, we could walk the linked list from sym->ns->parent->code
through ->next pointers and look for EXEC_BLOCK which has sym->ns as the
attached namespace, but that could be compile time expensive (consider
a function with a million of blocks in it and in each of them one or more
referenced parameters - that would be O(n^2) compile time).
The following patch instead checks the bit flag set only in EXEC_BLOCK
namespaces.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2019-02-01  Jakub Jelinek  <ja...@redhat.com>

        PR fortran/83246
        PR fortran/89084
        * trans-decl.c (generate_local_decl): Add referenced FL_PARAMETERs
        if sym->ns->construct_entities rather than if
        sym->ns->parent->code->op == EXEC_BLOCK.

        * gfortran.dg/pr89084.f90: New test.
        * gfortran.dg/lto/pr89084_0.f90: New test.
        * gfortran.dg/pr83246.f90: New test.

--- gcc/fortran/trans-decl.c.jj 2019-01-19 09:41:46.465393897 +0100
+++ gcc/fortran/trans-decl.c    2019-02-01 18:28:35.376176176 +0100
@@ -5735,10 +5735,7 @@ generate_local_decl (gfc_symbol * sym)
                          "imported at %L", sym->name, &sym->declared_at);
        }
 
-      if (sym->ns
-         && sym->ns->parent
-         && sym->ns->parent->code
-         && sym->ns->parent->code->op == EXEC_BLOCK)
+      if (sym->ns && sym->ns->construct_entities)
        {
          if (sym->attr.referenced)
            gfc_get_symbol_decl (sym);
--- gcc/testsuite/gfortran.dg/pr89084.f90.jj    2019-02-01 18:29:56.776826089 
+0100
+++ gcc/testsuite/gfortran.dg/pr89084.f90       2019-02-01 18:32:11.305594831 
+0100
@@ -0,0 +1,23 @@
+! PR fortran/89084
+! { dg-do run }
+
+integer function foo ()
+  write (*,*) 'foo'
+  block
+    integer, parameter :: idxs(3) = (/ 1, 2, 3 /)
+    integer :: i
+    foo = 0
+    do i = 1, size(idxs)
+      foo = foo + idxs(i)
+    enddo
+  end block
+end function foo
+program pr89084
+  integer :: i
+  interface
+    integer function foo ()
+    end function
+  end interface
+  i = foo ()
+  if (i.ne.6) stop 1
+end
--- gcc/testsuite/gfortran.dg/lto/pr89084_0.f90.jj      2019-02-01 
18:33:12.500579868 +0100
+++ gcc/testsuite/gfortran.dg/lto/pr89084_0.f90 2019-02-01 18:33:31.387266622 
+0100
@@ -0,0 +1,24 @@
+! PR fortran/89084
+! { dg-lto-do link }
+! { dg-lto-options {{ -O0 -flto }} }
+
+integer function foo ()
+  write (*,*) 'foo'
+  block
+    integer, parameter :: idxs(3) = (/ 1, 2, 3 /)
+    integer :: i
+    foo = 0
+    do i = 1, size(idxs)
+      foo = foo + idxs(i)
+    enddo
+  end block
+end function foo
+program pr89084
+  integer :: i
+  interface
+    integer function foo ()
+    end function
+  end interface
+  i = foo ()
+  if (i.ne.6) stop 1
+end
--- gcc/testsuite/gfortran.dg/pr83246.f90.jj    2019-02-01 20:19:04.567300205 
+0100
+++ gcc/testsuite/gfortran.dg/pr83246.f90       2019-02-01 20:18:02.446316150 
+0100
@@ -0,0 +1,9 @@
+! PR fortran/83246
+! { dg-do link }
+   program dusty_corner 
+   write(*,*)'BLOCK TESTS' 
+   MAKEDATAP: block
+   integer,parameter :: scratch(*)=[1,2,3]
+   write(*,*)scratch
+   endblock MAKEDATAP
+   end program dusty_corner

        Jakub

Reply via email to