This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, Fortran] PR34187 - Binding label got lost for private procedures of public generic procedures


:ADDPATCH fortran:

The way modules were read, the information about the binding label of
BIND(C) was sometimes not included.

This happend when the symbol itself was not directly loaded (e.g.
because it is private), but only later via load_needed.

The bug was found by the coworkers of Chris. The fix is simple: Copy the
bind_label in load_needed. (The other attributes are set via 
"mio_symbol (sym);".)

Build and regression tested on x86-64. OK for the trunk?

Tobias


PS: Would anyone mind if I changed the following of decl.c into a
"strcpy"? It should do exactly the same, is faster, looks less
complicated and is less error prone ("+1" is needed for strncpy).

        strncpy (sym->binding_label, binding_label,
                 strlen (binding_label)+1);

This syntax occurs 5 times. If we want to use strncpy, I'd prefer a
"GFC_MAX_SYMBOL_LEN + 1" as third argument.
2007-11-22  Tobias Burnus  <burnus@net-b.de>

	PR fortran/34187
	* module.c (load_needed): Ensure binding_label is not lost.

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

	PR fortran/34187
	* gfortran.dg/bind_c_usage_15.f90: New.

Index: gcc/fortran/module.c
===================================================================
--- gcc/fortran/module.c	(revision 130347)
+++ gcc/fortran/module.c	(working copy)
@@ -3419,6 +3419,7 @@ load_needed (pointer_info *p)
 
       sym = gfc_new_symbol (p->u.rsym.true_name, ns);
       sym->module = gfc_get_string (p->u.rsym.module);
+      strcpy (sym->binding_label, p->u.rsym.binding_label);
 
       associate_integer_pointer (p, sym);
     }
Index: gcc/testsuite/gfortran.dg/bind_c_usage_15.f90
===================================================================
--- gcc/testsuite/gfortran.dg/bind_c_usage_15.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/bind_c_usage_15.f90	(revision 0)
@@ -0,0 +1,29 @@
+! { dg-do run }
+!
+! PR fortran/34187
+! The binding label was not exported for private procedures
+! with public generic interfaces.
+!
+module mod
+  use iso_c_binding, only: c_int
+  implicit none
+  private
+  public :: gen, c_int
+  interface gen
+    module procedure  test
+  end interface gen
+contains
+  subroutine test(a) bind(c, name="myFunc")
+    integer(c_int), intent(out) :: a 
+    a = 17
+  end subroutine test
+end module mod
+
+program main
+  use mod
+  implicit none
+  integer(c_int) :: x
+  x = -44
+  call gen(x)
+  if(x /= 17) call abort()
+end program main

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]