GCC Bugzilla has been upgraded from version 4.4.9 to 5.0rc3. If you see any problem, please report it to bug 64968.
Bug 34133 - Bind(c,name="") should be rejected for dummies; F2008: allow bind(c) for internal procs
Summary: Bind(c,name="") should be rejected for dummies; F2008: allow bind(c) for inte...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Tobias Burnus
URL:
Keywords: accepts-invalid
Depends on:
Blocks: 32630
  Show dependency treegraph
 
Reported: 2007-11-17 12:57 UTC by Tobias Burnus
Modified: 2007-11-30 16:04 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-11-20 10:55:48


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2007-11-17 12:57:06 UTC
C1237 (R1225) A proc-language-binding-spec shall not be specified for an internal procedure.

However, gfortran accepts the following:

subroutine foo()
contains
  subroutine bar() bind (c)
  end subroutine bar
end subroutine foo

program main
  use iso_c_binding
  implicit none
contains
  subroutine test(c) bind(c)
    character(len=1,kind=c_char) :: c
  end subroutine test
end program main
Comment 1 Tobias Burnus 2007-11-17 18:19:27 UTC
Subject: Bug 34133

Author: burnus
Date: Sat Nov 17 18:19:16 2007
New Revision: 130260

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

        PR fortran/34133
        * decl.c (gfc_match_suffix,gfc_match_subroutine): Disallow
        bind(c) attribute for internal procedures.

2007-11-17  Tobias Burnus  <burnus@net-b.de>

        PR fortran/34133
        * gfortran.dg/bind_c_usage_9.f03: New.
        * gfortran.dg/interface_abstract_1.f90: Fix testcase.


Added:
    trunk/gcc/testsuite/gfortran.dg/bind_c_usage_9.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/interface_abstract_1.f90

Comment 2 Tobias Burnus 2007-11-17 18:21:31 UTC
FIXED on the trunk (4.3.0). (Not part of any branch.)
Comment 3 Chris Rickett 2007-11-19 18:13:22 UTC
(In reply to comment #2)
> FIXED on the trunk (4.3.0). (Not part of any branch.)
> 

i don't think this constraint exists in F08 (at least i cannot find it).
Comment 4 Tobias Burnus 2007-11-19 21:17:53 UTC
(In reply to comment #3)
> i don't think this constraint exists in F08 (at least i cannot find it).

You are right. However, there is still a constrain. Fortran 2003 has:

C1236 (R1225) A proc-language-binding-spec with a NAME= specifier shall not be specified in the function-stmt or subroutine-stmt of an interface body for an abstract interface or a dummy procedure.

C1237 (R1225) A proc-language-binding-spec shall not be specified for an internal procedure.

while  http://j3-fortran.org/doc/year/07/07-007r3.pdf has:
12.6.2.2 Function subprogram
C1252 (R1229) A proc-language-binding-spec with a NAME= specifier shall not be specified in the function-stmt or subroutine-stmt of an internal procedure, or of an interface body for an abstract interface or a dummy procedure.

Thus BIND(C) is allowed for internal procedures, but not BIND(C,name=...).

I think the idea is to allow such procedures, e.g., as actual argument; one thing one needs to check is the following: How does this work in terms of name mangling? Assume the following:

subroutine foo()
contains
  subroutine bar() bind(c)
  end subroutine bar
end subroutine foo

subroutine my() bind(c,name="bar")
end subroutine bar

This will cause name clashes of "bar". Internal procedures have the advantage that they are internal and have no name clashes problems. I wonder what symbol should be created for the internal procedure with bind(C) symbol. Maybe this is something to check in the standard and ask at the j3 mailing list.

The following is invalid per Fortran 2003 and 2008 and accepted by gfortran:

subroutine bb(a)
  interface
    subroutine a() bind(c, name="foo") ! name= for dummy variable
    end subroutine a
  end interface
end subroutine bb

For the latter, we need a patch which rejects this outright. For the former, I think a patch makes sense which allows it (w/o name=) for -std=gnu (and add a note to PR 33197 to change the GFC_STD_GNU to GFC_STD_F2008 as soon as gfortran has it.)
Comment 5 Tobias Burnus 2007-11-19 21:27:42 UTC
Ok. Found it in "15.5.2 Binding labels for procedures" of the Fortran 2008 draft with the expected wording:

"If a procedure has the BIND attribute with no NAME= specifier, and the procedure is not a dummy procedure, internal procedure, or procedure pointer, then the binding label of the procedure is the same as the name of the procedure using lower case letters. Otherwise, the procedure has no binding label."

Thus it can be handled the same way as gfortran does for 'bind(c,name="")': Simply use the Fortran name (which encodes the module name and parent procedure name).
Comment 6 patchapp@dberlin.org 2007-11-20 05:04:25 UTC
Subject: Bug number PR34133

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-11/msg00956.html
Comment 7 Tobias Burnus 2007-11-20 10:55:48 UTC
Assign bug to myself. I have a patch, which does:
- rejects bind(c) with -std=f2003 for internal function (was missing!)
- Allows for -std=gnu bind(c) for internal procedures, but
  rejects bind(c,name=...)
- Rejects binding names for dummy procedures
Now I only need to create a bunch of test cases.
Comment 8 patchapp@dberlin.org 2007-11-20 14:01:22 UTC
Subject: Bug number PR34133

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-11/msg01062.html
Comment 9 Tobias Burnus 2007-11-30 12:16:55 UTC
Subject: Bug 34133

Author: burnus
Date: Fri Nov 30 12:16:35 2007
New Revision: 130535

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

        PR fortran/34133
        * match.h: Add bool allow_binding_name to gfc_match_bind_c.
        * decl.c
        * (match_attr_spec,gfc_match_bind_c_stmt,gfc_match_entry):
        Adjust accordingly.
        (gfc_match_bind_c): Add allow_binding_name argument, reject
        binding name for dummy arguments.
        (gfc_match_suffix,gfc_match_subroutine): Make use of
        allow_binding_name.

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

        PR fortran/34133
        * gfortran.dg/bind_c_usage_9.f03: Fixes; add -std=f2003.
        * gfortran.dg/bind_c_usage_11.f03: New.
        * gfortran.dg/bind_c_usage_12.f03: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/bind_c_usage_11.f03
    trunk/gcc/testsuite/gfortran.dg/bind_c_usage_12.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/match.h
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/bind_c_usage_9.f03

Comment 10 Tobias Burnus 2007-11-30 16:04:50 UTC
FIXED on the trunk (4.3.0).