Bug 27546 - IMPORT is broken
IMPORT is broken
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: fortran
4.2.0
: P3 normal
: 4.3.0
Assigned To: Tobias Burnus
: ice-on-valid-code
Depends on:
Blocks: 20585
  Show dependency treegraph
 
Reported: 2006-05-11 06:05 UTC by Francois-Xavier Coudert
Modified: 2006-12-08 09:50 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.3.0
Last reconfirmed: 2006-11-07 22:01:15


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Francois-Xavier Coudert 2006-05-11 06:05:13 UTC
Reported by Harald Anlauf:
---------------------------
Hi,

the IMPORT statement of Fortran2003 is not yet implemented.
Trying to use it provokes an ICE:

module gfcbug29_import
  integer, parameter :: dp = kind (1d0)

  interface
     subroutine foo (x)
       import :: dp
       real (kind=dp) :: x
     end subroutine foo
  end interface

end module gfcbug29_import


% gfortran -c -std=f2003 gfcbug29.f90
 In file gfcbug29.f90:6

       import :: dp
      1
Error: Unclassifiable statement at (1)
gfcbug29.f90:0: internal compiler error: Segmentation fault

See the Fortran2003 draft, tables 2.1, 2.2, and section 12.3.2.1
about interface blocks.

Cheers,
-ha
Comment 1 Andrew Pinski 2006-05-12 04:32:12 UTC
Confirmed.
Comment 2 Tobias Burnus 2006-11-07 16:36:05 UTC
Syntax:
  IMPORT [[ :: ] import-name-list]

May only appear in the interface body, i.e.
  interface
     import
is wrong, but
  interface
    subroutine foo
      import
is ok.
(It would be nice if one could give a good error message for the first case - as for the case that one puts it outside an interface block.)

Current check is in decl.c:1216.

One needs to reject also
 interface
   type bar
   end type bar
   subroutine
      import bar
if bar does not exists in the host scoping unit.
Comment 3 Paul Thomas 2006-11-07 21:40:14 UTC
Have removed the rejects-valid keyword.

Paul
Comment 4 Tobias Burnus 2006-11-07 22:01:15 UTC
Accept. I have almost finished that patch :-)
Comment 5 patchapp@dberlin.org 2006-11-08 10:05:20 UTC
Subject: Bug number PR27546

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/2006-11/msg00466.html
Comment 6 Tobias Burnus 2006-11-15 15:46:54 UTC
Subject: Bug 27546

Author: burnus
Date: Wed Nov 15 15:46:42 2006
New Revision: 118857

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=118857
Log:
fortran/
2006-11-15  Tobias Burnus  <burnus@net-b.de>

       PR fortran/27546
       * decl.c (gfc_match_import,variable_decl):
         Add IMPORT support.
         (gfc_match_kind_spec): Fix typo in gfc_error.
       * gfortran.h (gfc_namespace, gfc_statement):
         Add IMPORT support.
       * parse.c (decode_statement,gfc_ascii_statement,
         verify_st_order): Add IMPORT support.
       * match.h: Add gfc_match_import.
       * gfortran.texi: Add IMPORT to the supported
         Fortran 2003 features.

testsuite/
 2006-11-15  Tobias Burnus  <burnus@net-b.de>

       PR fortran/27546
       * gfortran.dg/import.f90: New test.
       * gfortran.dg/import2.f90: New test.
       * gfortran.dg/import3.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/import.f90
    trunk/gcc/testsuite/gfortran.dg/import2.f90
    trunk/gcc/testsuite/gfortran.dg/import3.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/gfortran.texi
    trunk/gcc/fortran/match.h
    trunk/gcc/fortran/parse.c
    trunk/gcc/testsuite/ChangeLog

Comment 7 Tobias Burnus 2006-11-15 16:22:46 UTC
Fixed in 4.3 == trunk.
Comment 8 Tobias Burnus 2006-11-15 16:44:38 UTC
Reopened. I should have really read this bugreport and tested the example of comment 0. My test cases worked, but this one does not:

internal compiler error: module symbol dp in wrong namespace

#4  0x0000000000478002 in gfc_create_module_variable (sym=0xdddd10) at fortran/trans-decl.c:2761
#5  0x00000000004587de in traverse_ns (st=0xda3080, func=0x477f00 <gfc_create_module_variable>)
    at fortran/symbol.c:2603
#6  0x00000000004587c6 in traverse_ns (st=0xda25e0, func=0x477f00 <gfc_create_module_variable>)
    at fortran/symbol.c:2606
#7  0x00000000004648de in gfc_generate_module_code (ns=0x4) at fortran/trans.c:672


Using only "IMPORT":
       real (kind=dp) :: x
                 1
Error: Parameter 'dp' at (1) has not been declared or is a variable, which does not reduce to a constant expression
Comment 9 Tobias Burnus 2006-11-15 17:06:49 UTC
For
   IMPORT
the error occures in expr.c's check_init_expr
    case EXPR_VARIABLE:
      if (e->symtree->n.sym->attr.flavor == FL_PARAMETER)
        {
          t = simplify_parameter_variable (e, 0);
          break;
        }
      gfc_error ("Parameter '%s' at %L has not been declared or is "

It should have actually matched FL_PARAMETER, but for some reasons it has not.


For
  IMPORT :: dp
it happens in trans-decl.c's gfc_create_module_variable:
  /* Only output symbols from this module.  */
  if (sym->ns != module_namespace)
    {
      /* I don't think this should ever happen.  */
      internal_error ("module symbol %s in wrong namespace", sym->name);
    }

I don't see immediately how to fix this. If someone has a good spontaneous idea ... otherwise I try to understand how it should work.
Comment 10 Tobias Burnus 2006-11-15 20:50:28 UTC
For dp (= kind) I really need to find out where to modify this. Somehow this is not properly recognized as constant expression.
(Tested by using no "import" and commenting the check in variable_decl. This is essentially what happens with "import".)

 * * *

Some more tests:
If one changes the module to a "program" or only puts the "dp" into a module, but the interface into a "program", "import :: dp" works. ("import" does not.)
If the interface is in a module (same or different one than "dp"), the ICE occurs.

"Import" does not work at all for kind=...; it works, however, for "type(mytype)", regardless whether it is in a module or not. "import :: mytype" does not work in a module.
Comment 11 patchapp@dberlin.org 2006-11-18 10:45:34 UTC
Subject: Bug number PR27546

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/2006-11/msg01304.html
Comment 12 Tobias Burnus 2006-11-20 21:29:57 UTC
Subject: Bug 27546

Author: burnus
Date: Mon Nov 20 21:29:32 2006
New Revision: 119028

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=119028
Log:
fortran/
2006-11-17  Tobias Burnus  <burnus@net-b.de>

    PR fortran/27546
    * primary.c (gfc_match_rvalue): Added IMPORT support.

testsuite/
2006-11-17  Tobias Burnus  <burnus@net-b.de>

    PR fortran/27546
    * gfortran.dg/import.f90: Extended test.
    * gfortran.dg/import2.f90: Extended test.


Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/primary.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/import.f90
    trunk/gcc/testsuite/gfortran.dg/import2.f90

Comment 13 patchapp@dberlin.org 2006-11-28 14:45:55 UTC
Subject: Bug number PR27546

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/2006-11/msg01889.html
Comment 14 Tobias Burnus 2006-12-08 09:46:02 UTC
Subject: Bug 27546

Author: burnus
Date: Fri Dec  8 09:45:44 2006
New Revision: 119651

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=119651
Log:
fortran/
2006-12-08  Tobias Burnus  <burnus@net-b.de>

    PR fortran/27546
    * trans-decl.f90 (gfc_create_module_variable): Allow imported symbols
      in interface bodys in modules.

testsuite/
2006-12-08  Tobias Burnus  <burnus@net-b.de>

    PR fortran/27546
    * gfortran.dg/import4.f90: New test for IMPORT in modules. 


Added:
    trunk/gcc/testsuite/gfortran.dg/import4.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-decl.c
    trunk/gcc/testsuite/ChangeLog

Comment 15 Tobias Burnus 2006-12-08 09:50:08 UTC
Mark fixed. Hopefully, I didn't miss anything.