Bug 34187 - BIND(C): Public generic with private bind(c) specific does not use bind(C) name
Summary: BIND(C): Public generic with private bind(c) specific does not use bind(C) name
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Not yet assigned to anyone
Keywords: wrong-code
Depends on:
Blocks: 32630
  Show dependency treegraph
Reported: 2007-11-22 11:12 UTC by Tobias Burnus
Modified: 2007-11-24 00:13 UTC (History)
2 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2007-11-22 11:12:35 UTC
As reported by Chris:
For the following code, the bind(C) is ignored when calling the private specific subroutine "test" via calling the generic procedure "gen".
Result: The procedure "test_" is called and the linker complains.

If one makes "test" public, it works. As -fdump-parse-tree shows (after applying the fixes from PR34186), in "main" "test" has the "bind(c)" attribute.

subroutine test() bind(c)
end subroutine test

module mod
  public :: gen
  interface gen
     subroutine test() bind(c)
     end subroutine test
  end interface gen
end module mod

program main
  use mod
  call gen
end program main
Comment 1 Tobias Burnus 2007-11-22 11:56:53 UTC
Some more debugging. The problem is that in gfc_conv_function_call / gfc_sym_mangled_function_id of "main", is_bind_c=1 but binding_label = '\0'.

Actually, already for gfc_search_interface, I get sym=test and bind= '\0'.

Educated guess: The problem is in module.c; the binding label is properly written into the .mod file (from looking at it) but in load_generic_interfaces, the "gfc_get_symbol (p, NULL, &sym);" returns for p = "test" no binding name.
Comment 2 patchapp@dberlin.org 2007-11-22 19:03:02 UTC
Subject: Bug number PR34187

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/msg01165.html
Comment 3 Tobias Burnus 2007-11-24 00:11:47 UTC
Subject: Bug 34187

Author: burnus
Date: Sat Nov 24 00:11:38 2007
New Revision: 130386

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

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

        * decl.c (set_binding_label,gfc_match_bind_c): Replace
        strncpy by strcpy.

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

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


Comment 4 Tobias Burnus 2007-11-24 00:13:17 UTC
FIXED on the trunk (4.3.0). Does not affect earlier versions of gfortran.