Bug 33818 - [4.3 Regression] Bogus error "Variable 'str' is used at (1) before the ENTRY statement"
Summary: [4.3 Regression] Bogus error "Variable 'str' is used at (1) before the ENTRY...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks: 32834
  Show dependency treegraph
 
Reported: 2007-10-19 14:54 UTC by Tobias Burnus
Modified: 2007-10-20 11:39 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.2.2 4.1.2
Known to fail: 4.3.0
Last reconfirmed: 2007-10-19 15:10:44


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2007-10-19 14:54:48 UTC
Reduced from http://gcc.gnu.org/ml/fortran/2007-10/msg00280.html

The following gives the bogus error:

  write(lu,'(a)') 'UNIT '//UpperCase(UNAME(1))
                                             1
Error: Variable 'str' is used at (1) before the ENTRY statement in which it is a parameter

subroutine ExportZMX(lu)
  implicit real(selected_real_kind(15)) (a-h,o-z)
  character(*),parameter :: UNAME(1:1)=(/'XXX'/)
  write(lu,'(a)') 'UNIT '//UpperCase(UNAME(1))
  entry ExportSEQ(lu)
contains
  function UpperCase(str) result(res)
    character(*),intent(in) :: str
    character(len(str)) res
    res=str
  end function
end
Comment 1 Dominique d'Humieres 2007-10-19 15:07:36 UTC
The bug is not present in 4.2.2, and appeared before revision 129038.
Comment 2 Dominique d'Humieres 2007-10-19 15:12:56 UTC
It is not in gcc version 4.3.0 20070713.
Comment 3 Tobias Burnus 2007-10-19 15:15:19 UTC
Slightly further reduced test:

subroutine ExportZMX(lu)
  implicit none
  integer :: lu
  interface
    function UpperCase(str)
      character(*),intent(in) :: str
      character(len(str))     :: UpperCase ! Rejected
!     character(1)     :: UpperCase ! Works
    end function UpperCase
  end interface
  character, parameter :: UNAME ='X'
  write(lu,'(a)') 'UNIT '//UpperCase(UNAME) ! Rejected
!  write(lu,'(a)') UpperCase(UNAME) ! Works
  entry ExportSEQ(lu)
end
Comment 4 Tobias Burnus 2007-10-19 21:16:39 UTC
I'm not completely sure which bug is triggered that, but the error occurs for the expression
   character(len(str))     :: UpperCase

"str" is a dummy (of the interface function UpperCase) and despite being a dummy it is not a dummy of the current entry function (which is "ExportZMX").

The check assumes: Dummy + not-dummy of current function => Dummy of another Entry -> invalid.

The solution is to add a check whether the dummy in in the current name space or not.

I could not find any bit in the patches which caused this, but my un-educated guess would be http://gcc.gnu.org/viewcvs?view=rev&revision=127939 which added some character substring fixes.

Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c       (revision 129495)
+++ gcc/fortran/resolve.c       (working copy)
@@ -3935,7 +3935,7 @@ resolve_variable (gfc_expr *e)
       bool seen;

       /* If the symbol is a dummy...  */
-      if (sym->attr.dummy)
+      if (sym->attr.dummy && sym->ns == gfc_current_ns)
        {
          entry = gfc_current_ns->entries;
          seen = false;
@@ -3952,7 +3952,7 @@ resolve_variable (gfc_expr *e)
          if (!seen)
            {
              if (specification_expr)
-               gfc_error ("Variable '%s',used in a specification expression, "
+               gfc_error ("Variable '%s', used in a specification expression, "
                           "is referenced at %L before the ENTRY statement "
                           "in which it is a parameter",
                           sym->name, &cs_base->current->loc);
Comment 5 patchapp@dberlin.org 2007-10-20 04:24:19 UTC
Subject: Bug number PR 33818

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-10/msg01188.html
Comment 6 Tobias Burnus 2007-10-20 11:34:36 UTC
Subject: Bug 33818

Author: burnus
Date: Sat Oct 20 11:34:21 2007
New Revision: 129510

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=129510
Log:
2007-10-20  Tobias Burnus  <burnus@net-b.de>

        PR fortran/33818
        * resolve.c (resolve_variable): Check that symbol is in the same
        namespace as the entry function.

2007-10-20  Tobias Burnus  <burnus@net-b.de>

        PR fortran/33818
        * gfortran.dg/entry_dummy_ref_3.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/entry_dummy_ref_3.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog

Comment 7 Tobias Burnus 2007-10-20 11:39:24 UTC
FIXED on the trunk (4.3.0).