Bug 24545 - gfortran bug regarding interface block with named END INTERFACE statements
Summary: gfortran bug regarding interface block with named END INTERFACE statements
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.1.0
: P2 normal
Target Milestone: 4.0.3
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-10-26 16:54 UTC by Paul van Delst
Modified: 2005-10-28 21:02 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-10-26 17:05:50


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul van Delst 2005-10-26 16:54:29 UTC
Hello,

The code example listed at the end of this email fails to compile with gfortran 4.1.0 20051025 (experimental). Compiling like so:
  gfortran -c gfortran_test.f90
produces the error message:

 In file gfortran_test.f90:16
  END INTERFACE OPERATOR (.EqualTo.)
                                   1
Error: Expecting 'END INTERFACE OPERATOR (.compare_float.)' at (1)

This problem with recognizing the end interface statement flows on and produces a whole slew of (spurious) error messages on valid code.

If I change the source code line
  END INTERFACE OPERATOR (.EqualTo.)
to simply
  END INTERFACE
the code compiles just fine. However, I believe that using the syntax of
  END INTERFACE OPERATOR (.EqualTo.)
is standard Fortran95.

Thanks,

paulv

------<<cut here for gfortran_test.f90>>------
MODULE Compare_Float_Numbers
  IMPLICIT NONE

  PRIVATE
  PUBLIC :: Compare_Float
  PUBLIC :: OPERATOR (.EqualTo.)

  INTERFACE Compare_Float
    MODULE PROCEDURE Compare_Float_Single
    MODULE PROCEDURE Compare_Float_Double
  END INTERFACE Compare_Float

  INTERFACE OPERATOR (.EqualTo.)
    MODULE PROCEDURE Is_Equal_To_Single
    MODULE PROCEDURE Is_Equal_To_Double
  END INTERFACE OPERATOR (.EqualTo.)

  INTEGER, PARAMETER :: Single = SELECTED_REAL_KIND(6)  ! Single precision
  INTEGER, PARAMETER :: Double = SELECTED_REAL_KIND(15) ! Double precision

CONTAINS

  ! -- Is Equal To
  ELEMENTAL FUNCTION Is_Equal_To_Single( x, y ) RESULT( Equal_To )
    REAL( Single ), INTENT( IN )  :: x, y
    LOGICAL :: Equal_To
    Equal_To = ABS( x - y ) < SPACING( MAX(ABS(x),ABS(y)) )
  END FUNCTION Is_Equal_To_Single

  ELEMENTAL FUNCTION Is_Equal_To_Double( x, y ) RESULT( Equal_To )
    REAL( Double ), INTENT( IN )  :: x, y
    LOGICAL :: Equal_To
    Equal_To = ABS( x - y ) < SPACING( MAX(ABS(x),ABS(y)) )
  END FUNCTION Is_Equal_To_Double

  ! -- General floating point comparison
  ELEMENTAL FUNCTION Compare_Float_Single( x, y, ulp ) RESULT( Compare )
    REAL( Single ),           INTENT( IN )  :: x
    REAL( Single ),           INTENT( IN )  :: y
    INTEGER,        OPTIONAL, INTENT( IN )  :: ulp
    LOGICAL :: Compare
    REAL( Single ) :: Rel
    Rel = 1.0_Single
    IF ( PRESENT( ulp ) ) THEN
      Rel = REAL( ABS(ulp), Single )
    END IF
    Compare = ABS( x - y ) < ( Rel * SPACING( MAX(ABS(x),ABS(y)) ) )
  END FUNCTION Compare_Float_Single

  ELEMENTAL FUNCTION Compare_Float_Double( x, y, ulp ) RESULT( Compare )
    REAL( Double ),           INTENT( IN )  :: x
    REAL( Double ),           INTENT( IN )  :: y
    INTEGER,        OPTIONAL, INTENT( IN )  :: ulp
    LOGICAL :: Compare
    REAL( Double ) :: Rel
    Rel = 1.0_Double
    IF ( PRESENT( ulp ) ) THEN
      Rel = REAL( ABS(ulp), Double )
    END IF
    Compare = ABS( x - y ) < ( Rel * SPACING( MAX(ABS(x),ABS(y)) ) )
  END FUNCTION Compare_Float_Double

END MODULE Compare_Float_Numbers
------<<cut here for gfortran_test.f90>>------
Comment 1 kargls 2005-10-26 17:05:50 UTC
Here's a reduced code that shows the problem.  Gfortran is
not handling the END INTERFACE OPERATOR (.EqualTo.) correctly.
This confuses the heck out of the error recovery code.

MODULE Compare_Float_Numbers

  IMPLICIT NONE

  INTERFACE Compare_Float
    MODULE PROCEDURE Compare_Float_Single
  END INTERFACE Compare_Float

  INTERFACE OPERATOR (.EqualTo.)
    MODULE PROCEDURE Is_Equal_To_Single
  END INTERFACE OPERATOR (.EqualTo.)

CONTAINS

  FUNCTION Is_Equal_To_Single(x, y) RESULT(Equal_To)
    REAL(4), INTENT(IN) :: x, y
    LOGICAL :: Equal_To
    Equal_To = .true.
  END FUNCTION Is_Equal_To_Single

  FUNCTION Compare_Float_Single(x, y) RESULT(Compare)
    REAL(4), INTENT(IN) :: x, y
    LOGICAL :: Compare
    Compare = .true.
  END FUNCTION Compare_Float_Single

END MODULE Compare_Float_Numbers
Comment 2 Steven Bosscher 2005-10-26 18:54:09 UTC
Perhaps this cures it.

Index: interface.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/interface.c,v
retrieving revision 1.21
diff -u -3 -p -r1.21 interface.c
--- interface.c 21 Oct 2005 18:50:52 -0000      1.21
+++ interface.c 26 Oct 2005 18:53:39 -0000
@@ -295,7 +295,7 @@ gfc_match_end_interface (void)
       /* Comparing the symbol node names is OK because only use-associated
          symbols can be renamed.  */
       if (type != current_interface.type
-         || strcmp (current_interface.sym->name, name) != 0)
+         || strcmp (current_interface.uop->name, name) != 0)
        {
          gfc_error ("Expecting 'END INTERFACE OPERATOR (.%s.)' at %C",
                     current_interface.sym->name);
Comment 3 kargls 2005-10-28 20:06:03 UTC
Subject: Bug 24545

Author: kargl
Date: Fri Oct 28 20:05:56 2005
New Revision: 105953

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=105953
Log:
PR fortran/24545
* interface.c (gfc_match_end_interface): Fix typo in INTERFACE_USER_OP case.



Added:
    trunk/gcc/testsuite/gfortran.dg/interface_2.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/interface.c
    trunk/gcc/testsuite/ChangeLog

Comment 4 Steve Kargl 2005-10-28 20:07:30 UTC
Subject: Re:  gfortran bug regarding interface block with named END INTERFACE statements

On Wed, Oct 26, 2005 at 06:54:10PM -0000, steven at gcc dot gnu dot org wrote:
> 
> Index: interface.c
> ===================================================================
> RCS file: /cvs/gcc/gcc/gcc/fortran/interface.c,v
> retrieving revision 1.21
> diff -u -3 -p -r1.21 interface.c
> --- interface.c 21 Oct 2005 18:50:52 -0000      1.21
> +++ interface.c 26 Oct 2005 18:53:39 -0000
> @@ -295,7 +295,7 @@ gfc_match_end_interface (void)
>        /* Comparing the symbol node names is OK because only use-associated
>           symbols can be renamed.  */
>        if (type != current_interface.type
> -         || strcmp (current_interface.sym->name, name) != 0)
> +         || strcmp (current_interface.uop->name, name) != 0)
>         {
>           gfc_error ("Expecting 'END INTERFACE OPERATOR (.%s.)' at %C",
>                      current_interface.sym->name);
> 

Bootstrapped and regression tested  on amd64-*-freebsd.
I've committed the patch.

Comment 5 kargls 2005-10-28 20:57:23 UTC
Subject: Bug 24545

Author: kargl
Date: Fri Oct 28 20:57:17 2005
New Revision: 105962

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=105962
Log:
PR fortran/24545
* interface.c (gfc_match_end_interface): Fix typo in INTERFACE_USER_OP case.


Added:
    branches/gcc-4_0-branch/gcc/testsuite/gfortran.dg/interface_2.f90
Modified:
    branches/gcc-4_0-branch/gcc/fortran/ChangeLog
    branches/gcc-4_0-branch/gcc/fortran/interface.c
    branches/gcc-4_0-branch/gcc/testsuite/ChangeLog

Comment 6 kargls 2005-10-28 20:58:28 UTC
Fixed.