User account creation filtered due to spam.

Bug 32600 - [ISO Bind C] C_F_POINTER w/o SHAPE should not be a library function
Summary: [ISO Bind C] C_F_POINTER w/o SHAPE should not be a library function
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 enhancement
Target Milestone: ---
Assignee: Francois-Xavier Coudert
URL:
Keywords: missed-optimization
Depends on:
Blocks: 32630
  Show dependency treegraph
 
Reported: 2007-07-02 22:54 UTC by Tobias Burnus
Modified: 2008-05-25 17:55 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-03-13 14:37:10


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2007-07-02 22:54:06 UTC
The code

use iso_c_binding
integer, target :: i
type(c_ptr) :: bar
bar = c_loc(i)
end

produces:

  bar = c_loc (&i);

g95 produces:
  bar = &i;;
and NAG f95:
  bar_ = (char*) &i_;

Analogously for C_FUNPOINTER:
---------------
use iso_c_binding
interface
  subroutine bar() bind(c)
  end subroutine bar
end interface
type(c_funptr) :: fptr
fptr = c_funloc(bar)
end
---------------

gfortran:
  void * fptr;
  fptr = c_funloc (bar);
g95:
  void (*<T34>) (void) fptr;
  fptr = bar;;
NAG f95:
  typedef void * __NAGf90_MODULE_iso_c_binding_DT_c_ptr;
  typedef void (* __NAGf90_MODULE_iso_c_binding_DT_c_funptr)();
  auto __NAGf90_MODULE_iso_c_binding_DT_c_funptr fptr_;
  fptr_ = (void(*)())bar;
Comment 1 Tobias Burnus 2007-07-02 23:09:59 UTC
Analogously for c_f_pointer (without SHAPE) and c_f_funpointer:

use iso_c_binding
implicit none
integer, target :: tgt
type(c_ptr) :: cptr
integer, pointer :: ptr
 cptr = c_loc(tgt)
 call c_f_pointer(cptr,ptr)
end


gfortran:
  c_f_pointer_i4 (cptr, &ptr, 0B);
g95:
  ptr = cptr;;
NAG f95:
  ptr_ = cptr_;


For shape, one can also consider generate the code directly.
gfortran and g95 call a library function but NAG f95 generates the C code directly:

use iso_c_binding
implicit none
integer, target :: tgt(10)
type(c_ptr) :: cptr
integer, pointer :: ptr(:)
 cptr = c_loc(tgt)
 call c_f_pointer(cptr,ptr, (/ 10 /))
end
Comment 2 kargl 2007-07-03 03:55:01 UTC
This just an optimization request, right?  The functions calls work?
Comment 3 Tobias Burnus 2007-07-03 05:27:28 UTC
(In reply to comment #2)
> This just an optimization request, right?  The functions calls work?
Yes - at least all my test programs work.

Though there might be some combinations of c_f_pointer which don't work; at least I don't remember seeing a patch after Chris wrote 
TODO: "1) add versions of c_f_pointer for complex type/kind combos"
http://gcc.gnu.org/ml/fortran/2007-02/msg00558.html

But I might have simply missed the patch.
Comment 4 patchapp@dberlin.org 2007-07-18 23:30:21 UTC
Subject: Bug number PR 32600

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-07/msg01565.html
Comment 5 Tobias Burnus 2007-07-19 06:14:31 UTC
Subject: Bug 32600

Author: burnus
Date: Thu Jul 19 06:14:19 2007
New Revision: 126744

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126744
Log:
2007-07-19  Christopher D. Rickett  <crickett@lanl.gov>

	PR fortran/32600
	* trans-expr.c (gfc_conv_function_call): Inline C_LOC.


2007-07-19  Christopher D. Rickett  <crickett@lanl.gov>

	PR fortran/32600
	* libgfortran/intrinsics/iso_c_binding.c: Remove C_LOC.
	* libgfortran/intrinsics/iso_c_binding.h: Ditto.
	* libgfortran/gfortran.map: Ditto.


Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-expr.c
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/gfortran.map
    trunk/libgfortran/intrinsics/iso_c_binding.c
    trunk/libgfortran/intrinsics/iso_c_binding.h

Comment 6 Andrew Pinski 2007-07-21 08:04:20 UTC
Fixed.
Comment 7 Andrew Pinski 2007-07-21 08:04:59 UTC
Wait only C_LOC was fixed.
Comment 8 Tobias Burnus 2007-07-21 20:17:56 UTC
Besides c_funloc (patch submitted) and c_f_pointer (scalar case, i.e. no SHAPE) also c_associated (c_associated_1/c_associated_2) can be moved into trans*.c

The code for c_associated is essentially the same as for Fortran's ASSOCIATED, except there is no need for checking the array case. (Cf. trans-intrinsic.c's gfc_conv_associated.)

(Side note: I miss a __iso_c_binding_ prefix for these library routines, currently one gets in the dump, e.g., "c_f_pointer_i4" instead of the expected "__iso_c_binding_c_f_pointer_i4"; but libgfortran only exports the latter?!?)
Comment 9 patchapp@dberlin.org 2007-07-22 06:10:12 UTC
Subject: Bug number PR 32600

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-07/msg01540.html
Comment 10 Tobias Burnus 2007-07-23 06:03:44 UTC
Subject: Bug 32600

Author: burnus
Date: Mon Jul 23 06:03:33 2007
New Revision: 126835

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126835
Log:
2007-07-23  Christopher D. Rickett  <crickett@lanl.gov>
	    Tobias Burnus  <burnus@net-b.de>

	PR fortran/32600
	* trans-expr.c (gfc_conv_function_call): Handle c_funloc.
	* trans-types.c: Add pfunc_type_node.
	(gfc_init_types,gfc_typenode_for_spec): Use it.
	* resolve.c (gfc_iso_c_func_interface): Fix whitespace and
	improve error message.

2007-07-23  Christopher D. Rickett  <crickett@lanl.gov>

	PR fortran/32600
	* intrinsics/iso_c_binding.c (c_funloc): Remove.
	* intrinsics/iso_c_binding.h: Remove c_funloc.
	* gfortran.map: Ditto.

2007-07-23  Christopher D. Rickett  <crickett@lanl.gov>

	PR fortran/32600
	* gfortran.dg/c_funloc_tests_5.f03: New.
	* gfortran.dg/c_funloc_tests_5.f04: New.
	* gfortran.dg/c_funloc_tests_4_driver.c: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/c_funloc_tests_4.f03
    trunk/gcc/testsuite/gfortran.dg/c_funloc_tests_4_driver.c
    trunk/gcc/testsuite/gfortran.dg/c_funloc_tests_5.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/fortran/trans-types.c
    trunk/gcc/testsuite/ChangeLog
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/gfortran.map
    trunk/libgfortran/intrinsics/iso_c_binding.c
    trunk/libgfortran/intrinsics/iso_c_binding.h

Comment 11 patchapp@dberlin.org 2007-10-15 01:07:23 UTC
Subject: Bug number PR 32600

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-10/msg00775.html
Comment 12 Tobias Burnus 2007-10-15 19:59:19 UTC
Subject: Bug 32600

Author: burnus
Date: Mon Oct 15 19:58:55 2007
New Revision: 129367

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=129367
Log:
2007-10-15 Christopher D. Rickett <crickett@lanl.gov>

        PR fortran/32600
        * trans-expr.c (gfc_conv_function_call): Generate code to inline
        c_associated.
        * symbol.c (get_iso_c_sym): Preserve from_intmod and
        * intmod_sym_id
        attributes in the resolved symbol.
        * resolve.c (gfc_iso_c_sub_interface): Remove dead code.


2007-10-15 Christopher D. Rickett <crickett@lanl.gov>

        PR fortran/32600
        * libgfortran/intrinsics/iso_c_binding.c: Remove c_associated_1
        and c_associated_2.
        * libgfortran/intrinsics/iso_c_binding.h: Ditto.
        * libgfortran/gfortran.map: Ditto.


Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/symbol.c
    trunk/gcc/fortran/trans-expr.c
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/gfortran.map
    trunk/libgfortran/intrinsics/iso_c_binding.c
    trunk/libgfortran/intrinsics/iso_c_binding.h

Comment 13 Tobias Burnus 2007-10-15 20:00:30 UTC
Last missing part: C_F_POINTER() in the absence of SHAPE should be in the front end and not a library call.
Comment 14 Tobias Burnus 2008-05-25 17:52:48 UTC
Subject: Bug 32600

Author: burnus
Date: Sun May 25 17:52:03 2008
New Revision: 135877

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=135877
Log:
2008-05-25  Tobias Burnus  <burnus@net-b.de>

        PR fortran/32600
        * trans-expr.c (gfc_conv_function_call): Remove library
        call for c_f_pointer with scalar Fortran pointers and for
        c_f_procpointer.

2008-05-25  Tobias Burnus  <burnus@net-b.de>

        PR fortran/32600
        * intrinsics/iso_c_binding.c (c_f_procpointer): Remove.
        * intrinsics/iso_c_binding.h (c_f_procpointer): Remove.
        * gfortran.map (c_f_procpointer): Remove.

2008-05-25  Tobias Burnus  <burnus@net-b.de>

        PR fortran/32600
        * gfortran.dg/c_f_pointer_tests_3.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/c_f_pointer_tests_3.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/testsuite/ChangeLog
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/gfortran.map
    trunk/libgfortran/intrinsics/iso_c_binding.c
    trunk/libgfortran/intrinsics/iso_c_binding.h

Comment 15 Tobias Burnus 2008-05-25 17:55:22 UTC
FIXED on the trunk (4.4).