This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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] PR40898 - Fix passing strings with STDCALL aand BIND(C)


When passing strings, gfortran appends a hidden argument with
the string length. Using BIND(C), that should not happen. It
was fixed for the generation of the call and when when generating
a function, but for external functions (with interface), this
change was forgotten.

The practical consequence was very little (TREE_DECL <-> call
inconsistency), except for Windows with STDCALL as there the
function calls are decorated by @<n> (n = argument size to pop
off the stack).

For the return value there is no problem as this is already
dealt with (return by argument == false).


The change in trans-decl.c was detected when running the
testsuite. I am not sure whether the attr.entry_master check
is needed, but in any case the master function should have
character length arguments, when any of its associated entry
procedures does not have BIND(C). (Always present is easier
than checking all other functions for being bind(C).)


Build and regtested on x86-64-linux. FX successfully tested
the test case of the PR (with the trans-type.c patch only)
a cross compiler (see PR). OK for the trunk?

Tobias

PS: I have not included a test case; if someone thinks, we can
add a Window-only one doing a link test.
2009-07-29  Tobias Burnus  <burnus@net-b.de>

	PR fortran/40898
	* trans-types.c (gfc_get_function_type): Do not add hidden
	string-length argument for BIND(C) procedures.
	* trans-decl.c (create_function_arglist): Skip over nonexisting
	string-length arguments for BIND(C) procedures.

Index: gcc/fortran/trans-types.c
===================================================================
--- gcc/fortran/trans-types.c	(revision 150203)
+++ gcc/fortran/trans-types.c	(working copy)
@@ -2249,7 +2310,7 @@ gfc_get_function_type (gfc_symbol * sym)
 	     Contained procedures could pass by value as these are never
 	     used without an explicit interface, and cannot be passed as
 	     actual parameters for a dummy procedure.  */
-	  if (arg->ts.type == BT_CHARACTER)
+	  if (arg->ts.type == BT_CHARACTER && !sym->attr.is_bind_c)
             nstr++;
 	  typelist = gfc_chainon_list (typelist, type);
 	}
Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c	(revision 150203)
+++ gcc/fortran/trans-decl.c	(working copy)
@@ -1724,7 +1771,8 @@ create_function_arglist (gfc_symbol * sy
 
       type = TREE_VALUE (typelist);
 
-      if (f->sym->ts.type == BT_CHARACTER)
+      if (f->sym->ts.type == BT_CHARACTER
+	  && (!sym->attr.is_bind_c || sym->attr.entry_master))
 	{
 	  tree len_type = TREE_VALUE (hidden_typelist);
 	  tree length = NULL_TREE;

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