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


hi Steve,

first, a comment on the code snippet you gave: the reason you have to add -fno-underscoring is because your main program forgets to say 'use c_char_tests', so sub0 gets implicitly declared.

second, i think i've tracked down what was causing the problem with the code snippet. the call to sub0 gets converted (gfc_conv_function_call) before the generate_local_decls runs for param_test. this means that the symbols for the dummy args in the call still say they're an array_type, so the actuals given by sub0() are converted to array_type. i think this means that the fixup done for by-value character dummies in generate_local_decl must also be done when mapping actuals to formals in gfc_conv_function_call. i've attached a patch that does this. it's been bootstrapped and regtested on x86 and x86_64 linux with no new failures, but the real test is whether they'll work for you. :-)

thanks for all of your help in tracking down this bug.

Chris

PS: the tree dump did not change with this patch, but the output from debug_tree does and seems as i'd expect.

On Fri, 27 Jul 2007, Steve Ellcey wrote:

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 ();
}

Attachment: icb_pr32732.diff
Description: Text document


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