[Patch, Fortran] PR34079 - BIND(C) and characters - unneeded character length passed

FX Coudert fxcoudert@gmail.com
Sat Nov 17 01:26:00 GMT 2007


:REVIEWMAIL:

Hi Tobias,

> This patch simply does not generate the extra argument(s) when  
> calling a
> BIND(C) procedure.

We also need to not consider these extra arguments when creating code  
for procedures, and also for function results (and probably also when  
creating the DECLs for these functions, which is handled in a  
different place IIRC). For example, with your patch, the following code:

subroutine foo(x) bind(c)
   character(len=1) :: x
   print *, x
end subroutine foo

function bar(x) bind(c)
   character(len=1) :: x, bar
   bar = x
end function bar

program test
   interface
     subroutine foo(x) bind(c)
       character(len=1) :: x
     end subroutine foo

     function bar(x) bind(c)
       character(len=1) :: x, bar
     end function bar
   end interface
   character(len=1) :: x

   call foo(" ")
   x = " "
   print *, bar(x)
end program test

generates the following code (excerpts from the tree dump):

foo (x, _x)    /* there shouldn't be a _x here */
{
   [...]
}

bar (__result, .__result, x, _x)  /* there should be neither _x  
nor .__result here */
{
   (*__result)[1]{lb: 1 sz: 1} = (*x)[1]{lb: 1 sz: 1};
}

test ()
{
   foo (&" "[1]{lb: 1 sz: 1}); /* this one is correct, per your  
patch; I don't know if the DECL for the function is correct, though;  
I need to check. */

   [...]

   bar ((char[1:1] *) &str.3, 1, &x[1]{lb: 1 sz: 1}); /* this one is  
half correct, because there's still an extra 1 as second argument */
}


I'll try to give more pointers to where this should be fixed, when I  
have time (I have looked at this code multiple times, while trying to  
get unique DECLs per function, including correct list of arg types).  
There might also be other subtleties, but I wanted to give you this  
heads-up as soon as possible.

FX

PS: I was truly amazed at the regexps in your testcases! that's great  
(and probably hard) work



More information about the Fortran mailing list