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] PR 37201 - fix character-returning bind(c) functions


This patch fixes a left over of PR 34079, which partially fixed
character-returning function, which then worked in assignments but not
as actual argument to other functions or in I/O statements.

Build & regtesting (libgomp [finished] and check-gfortran [almost finished]).
OK for the trunk (when regtesting is successful)?

Tobias
2008-08-24  Tobias Burnus  <burnus@net-b.de>

	PR fortran/37201
	* trans-expr.c (gfc_conv_function_call): Add string_length
	for character-returning bind(C) functions.

2008-08-24  Tobias Burnus  <burnus@net-b.de>

	PR fortran/37201
	* gfortran.dg/bind_c_usage_17.f90: New.
	* gfortran.dg/bind_c_usage_17_c.c: New.

Index: gcc/fortran/trans-expr.c
===================================================================
--- gcc/fortran/trans-expr.c	(Revision 139531)
+++ gcc/fortran/trans-expr.c	(Arbeitskopie)
@@ -2677,7 +2677,9 @@ gfc_conv_function_call (gfc_se * se, gfc
   gfc_finish_interface_mapping (&mapping, &se->pre, &se->post);
 
   ts = sym->ts;
-  if (ts.type == BT_CHARACTER && !sym->attr.is_bind_c)
+  if (ts.type == BT_CHARACTER && sym->attr.is_bind_c)
+    se->string_length = build_int_cst (gfc_charlen_type_node, 1);
+  else if (ts.type == BT_CHARACTER)
     {
       if (sym->ts.cl->length == NULL)
 	{
Index: gcc/testsuite/gfortran.dg/bind_c_usage_17_c.c
===================================================================
--- gcc/testsuite/gfortran.dg/bind_c_usage_17_c.c	(Revision 0)
+++ gcc/testsuite/gfortran.dg/bind_c_usage_17_c.c	(Revision 0)
@@ -0,0 +1,4 @@
+/* PR fortran/37201.
+   Linked with bind_c_usage_17.f90.  */
+
+char cdir(void){return '/';}
Index: gcc/testsuite/gfortran.dg/bind_c_usage_17.f90
===================================================================
--- gcc/testsuite/gfortran.dg/bind_c_usage_17.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/bind_c_usage_17.f90	(Revision 0)
@@ -0,0 +1,38 @@
+! { dg-do run }
+! { dg-additional-sources bind_c_usage_17_c.c }
+!
+! PR fortran/37201
+!
+! 
+!
+MODULE mod
+  INTERFACE
+    FUNCTION cdir() BIND(C,name="cdir") RESULT(r)
+      USE iso_c_binding
+      CHARACTER(kind=C_CHAR) :: r
+    END FUNCTION
+  END INTERFACE
+END MODULE
+
+PROGRAM test
+  USE mod
+  integer :: i = -43
+  character(len=1) :: str1
+  character(len=4) :: str4
+  str1 = 'x'
+  str4 = 'xyzz'
+  str1 = cdir()
+  if(str1 /= '/') call abort()
+  str4 = cdir()
+  if(str4 /= '/' .or. ichar(str4(2:2)) /= 32) call abort()
+  i   = ICHAR(cdir())
+  if (i /= 47) call abort()
+  str4 = 'xyzz'
+  WRITE(str4,'(a)') cdir()
+  if(str4 /= '/' .or. ichar(str4(2:2)) /= 32) call abort()
+  str4 = 'xyzz'
+  WRITE(str4,'(i0)') ICHAR(cdir())
+  if(str4 /= '47' .or. ichar(str4(3:3)) /= 32) call abort()
+END PROGRAM
+
+! { dg-final { cleanup-modules "mod" } }

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