This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix bind(c, name='x') result(y) functions
- From: Tobias Burnus <burnus at net-b dot de>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Mon, 30 Mar 2009 15:54:58 +0200
- Subject: Re: [PATCH] Fix bind(c, name='x') result(y) functions
- References: <20090330134008.GD3160@tyan-ft48-01.lab.bos.redhat.com>
Hi Jakub,
Jakub Jelinek wrote:
> Bootstrapped/regtested on x86_64-linux, ok for trunk? What about 4.4?
>
OK for the trunk. I think 4.4 is OK as the patch is simple.
Tobias
> 2009-03-30 Jakub Jelinek <jakub@redhat.com>
>
> * trans-types.c (gfc_sym_type, gfc_return_by_reference): For
> sym->attr.result check sym->ns->proc_name->attr.is_bind_c.
>
> * gfortran.dg/bind_c_usage_19.f90: New test.
>
> --- gcc/fortran/trans-types.c.jj 2009-01-13 18:32:16.000000000 +0100
> +++ gcc/fortran/trans-types.c 2009-03-30 13:16:06.000000000 +0200
> @@ -1632,8 +1632,11 @@ gfc_sym_type (gfc_symbol * sym)
> if (sym->backend_decl && !sym->attr.function)
> return TREE_TYPE (sym->backend_decl);
>
> - if (sym->ts.type == BT_CHARACTER && sym->attr.is_bind_c
> - && (sym->attr.function || sym->attr.result))
> + if (sym->ts.type == BT_CHARACTER
> + && ((sym->attr.function && sym->attr.is_bind_c)
> + || (sym->attr.result
> + && sym->ns->proc_name
> + && sym->ns->proc_name->attr.is_bind_c)))
> type = gfc_character1_type_node;
> else
> type = gfc_typenode_for_spec (&sym->ts);
> @@ -1962,7 +1965,11 @@ gfc_return_by_reference (gfc_symbol * sy
> if (sym->attr.dimension)
> return 1;
>
> - if (sym->ts.type == BT_CHARACTER && !sym->attr.is_bind_c)
> + if (sym->ts.type == BT_CHARACTER
> + && !sym->attr.is_bind_c
> + && (!sym->attr.result
> + || !sym->ns->proc_name
> + || !sym->ns->proc_name->attr.is_bind_c))
> return 1;
>
> /* Possibly return complex numbers by reference for g77 compatibility.
> --- gcc/testsuite/gfortran.dg/bind_c_usage_19.f90.jj 2009-03-30 13:02:25.000000000 +0200
> +++ gcc/testsuite/gfortran.dg/bind_c_usage_19.f90 2009-03-30 13:02:56.000000000 +0200
> @@ -0,0 +1,31 @@
> +! { dg-do compile }
> +function return_char1(i) bind(c,name='return_char1')
> + use iso_c_binding
> + implicit none
> + integer(c_int) :: i
> + character(c_char) :: j
> + character(c_char) :: return_char1
> +
> + j = achar(i)
> + return_char1 = j
> +end function return_char1
> +function return_char2(i) result(output) bind(c,name='return_char2')
> + use iso_c_binding
> + implicit none
> + integer(c_int) :: i
> + character(c_char) :: j
> + character(c_char) :: output
> +
> + j = achar(i)
> + output = j
> +end function return_char2
> +function return_char3(i) bind(c,name='return_char3') result(output)
> + use iso_c_binding
> + implicit none
> + integer(c_int) :: i
> + character(c_char) :: j
> + character(c_char) :: output
> +
> + j = achar(i)
> + output = j
> +end function return_char3
>
> Jakub
>
>