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]

Re: [Bug fortran/32732] [Bind C] Character scalars are passed as arrays


So, I looked at gfortran.dg/c_char_tests.f03 to see why it still fails
on IA64 HP-UX.  It looks like the previous patch handles functions that
are called with C bindings but it doesn't handle one Fortran routine
calling another Fortran routine with C bindings.  The caller is using
Fortran semantics while the callee is expecting C semantics.  If you
look at the tree dump below and the call to param_test from sub0, you
see strings intead of just characters and I think that is the problem.

I cut down the original test case to create a fortran only testcase
(requires -fno-underscoring) which is the following:

module c_char_tests
  use, intrinsic :: iso_c_binding, only: c_char
  implicit none
contains
  subroutine param_test(my_char, my_char_2) bind(c)
    character(c_char), value :: my_char
    character(c_char), value :: my_char_2
    if(my_char /= c_char_'y') call abort()
    if(my_char_2 /= c_char_'z') call abort()
  end subroutine param_test

  subroutine sub0() bind(c)
    call param_test('y', 'z')
  end subroutine sub0
end module c_char_tests

program main
  call sub0()
end program main

---------

When I dump the tree (x.f03.003t.original), I see:

sub0 ()
{
  param_test ("y", "z", 1, 1);


param_test (my_char, my_char_2, _my_char, _my_char_2)
{
  if (my_char != 121)
    {
      _gfortran_abort ();
    }
  if (my_char_2 != 122)
    {
      _gfortran_abort ();
    }

MAIN__ ()
{
  static int4 options.2[7] = {68, 127, 0, 0, 0, 1, 0};

  _gfortran_set_options (7, (void *) &options.2);
  sub0 ();
}


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