Bug 36275 - [F03] Binding label can be any scalar char initialisation expression
Summary: [F03] Binding label can be any scalar char initialisation expression
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: 5.0
Assignee: Francois-Xavier Coudert
URL:
Keywords: rejects-valid
: 38838 (view as bug list)
Depends on:
Blocks: 32630
  Show dependency treegraph
 
Reported: 2008-05-20 09:58 UTC by Francois-Xavier Coudert
Modified: 2014-06-29 14:15 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-05-24 20:08:36


Attachments
proposed patch (1.44 KB, patch)
2008-09-03 21:44 UTC, Mikael Morin
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Francois-Xavier Coudert 2008-05-20 09:58:39 UTC
The following is legal:

function x(z) bind(C,name='x'//'f')
  integer :: z, x
end function x

as the Standard (F2003) only says:

R509: language-binding-spec is BIND (C [, NAME = scalar-char-initialization-expr ])
C540: The scalar-char-initialization-expr shall be of default character kind.

So, any scalar char initialisation expression of default character kind is fair game. This will require removing a good part of the code in gfc_match_bind_c(), and call more generic routines instead, so it's not really bad news (and it also requires remove the gfc_match_name_C function).
Comment 1 Francois-Xavier Coudert 2008-05-20 10:09:55 UTC
And there is more to it (with import statements), see the rest of the thread at http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/148d078cda002dc1#
Comment 2 Tobias Burnus 2008-05-20 16:51:17 UTC
The other problem mentioned in the thread is the following bogus warning:


   procedure(stub), bind(C,name='cacosf') :: my_ACOS ! Compiles
                                                   1
Warning: Variable 'my_acos' at (1) may not be a C interoperable kind but it is bind(c)


I think it appeared after 2008-05-01-Rev134843 and should be related to one of the procedure patches. Test case:


 module trig_sp
   use ISO_C_BINDING
   integer, parameter :: rkind = C_FLOAT
   integer, parameter :: ckind = C_FLOAT_COMPLEX
   abstract interface
      function stub(z) bind(C)
         import rkind, ckind
         complex(ckind), value :: z
         complex(ckind) stub
      end function stub
   end interface
   procedure(stub), bind(C,name='cacosf') :: my_ACOS ! Compiles
end module trig_sp
Comment 3 janus 2008-05-28 21:58:27 UTC
The problem in comment #2 was indeed introduced by my rev. 134867, and can be fixed by the following patch:

Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c       (revision 136130)
+++ gcc/fortran/resolve.c       (working copy)
@@ -7751,6 +7751,7 @@ resolve_symbol (gfc_symbol *sym)
        {
          sym->ts.type = sym->ts.interface->ts.type;
          sym->ts.kind = sym->ts.interface->ts.kind;
+         sym->ts.is_c_interop = sym->ts.interface->ts.is_c_interop;
          sym->attr.function = sym->ts.interface->attr.function;
          sym->attr.subroutine = sym->ts.interface->attr.subroutine;
          copy_formal_args (sym, sym->ts.interface);
Comment 4 janus 2008-06-04 21:05:18 UTC
Subject: Bug 36275

Author: janus
Date: Wed Jun  4 21:04:32 2008
New Revision: 136372

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=136372
Log:
2008-06-04  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/36322
	PR fortran/36275
	* resolve.c (resolve_symbol): Correctly copy the interface for a
	PROCEDURE declaration.


2008-06-04  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/36322
	PR fortran/36275
	* gfortran.dg/proc_decl_2.f90: Extended.

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

Comment 5 janus 2008-06-04 21:10:28 UTC
Rev. 136372 fixes the issue from comment #2 (but not the original test case in comment #0).
Comment 6 Mikael Morin 2008-09-03 21:44:22 UTC
Created attachment 16215 [details]
proposed patch

With this patch the first testcase compiles with two warnings. 
It doesn't handle import statements as it is far less trivial ;)
I'll have to see more in details what was said on the c.l.f thread. 
Awaiting constructive (or destructive if you prefer) comments, advices, screams, ...
Comment 7 Francois-Xavier Coudert 2009-05-24 20:07:47 UTC
*** Bug 38838 has been marked as a duplicate of this bug. ***
Comment 8 Francois-Xavier Coudert 2009-05-24 20:08:36 UTC
PR38838 has additional testcases:

  subroutine test() bind(c, name=trim("Hello   "))
  end

and

  subroutine test() bind(c, name=1_"name")
  end
Comment 9 Daniel Franke 2009-12-10 19:10:58 UTC
See also PR38839 for expanded character set.
Comment 10 janus 2012-10-07 11:28:29 UTC
Note that arbitrary long binding names have been implemented in the meantime (PR51808).

A fix for this PR should obviously maintain that feature (which Mikael's patch in comment 6 does not seem to do).
Comment 11 Francois-Xavier Coudert 2014-06-08 22:35:13 UTC
Patch proposed here, somewhat based on Mikael's patch in comment #6:
https://gcc.gnu.org/ml/fortran/2014-06/msg00090.html
Comment 12 Francois-Xavier Coudert 2014-06-29 14:14:50 UTC
Author: fxcoudert
Date: Sun Jun 29 14:14:16 2014
New Revision: 212123

URL: https://gcc.gnu.org/viewcvs?rev=212123&root=gcc&view=rev
Log:
	PR fortran/36275
	PR fortran/38839

	* decl.c (check_bind_name_identifier): New function.
	(gfc_match_bind_c): Match any constant expression as binding
	label.
	* match.c (gfc_match_name_C): Remove.

	* gfortran.dg/binding_label_tests_2.f03: Adjust error messages.
	* gfortran.dg/binding_label_tests_27.f90: New file.

Added:
    trunk/gcc/testsuite/gfortran.dg/binding_label_tests_27.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/match.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/binding_label_tests_2.f03
Comment 13 Francois-Xavier Coudert 2014-06-29 14:15:54 UTC
Fixed on trunk.