[Patch, fortran] [4/4] C binding access to C_PTR type: main fix

Mikael Morin mikael.morin@sfr.fr
Sat Mar 2 16:54:00 GMT 2013


This is the main part of the patch.
A new argument "hidden" is added to generate_isocbinding_symbol, telling whether
we want the symbol accessible or not.
The code trying to reuse existing symbols is rewritten as follows:
 - A big condition containing two internal assignments is extracted into a new
 function: check_iso_c_symbol.
 - We make two attempts to look for the symbol, and use the new function to check
 for symbol match each time.  First, we try to find the symbol under its local
 (possibly renamed) name.  Then we fall back to look it up under its real name.

The code creating new symtrees doesn't use gfc_get_sym_tree anymore, as it
wouldn't honor "hidden";  it uses either gfc_new_symtree or
gfc_get_unique_symtree instead, depending on "hidden".

The same is done in the hunk dealing with creating the derived type symtree
(accessible with a capitalized first letter name).  I also changed tmp_sym->name
to name there as it made more sense to me (local name instead of real one).  I'm
not completely sure that it's correct though.

-------------- next part --------------
2013-03-02  Mikael Morin  <mikael@gcc.gnu.org>

	PR fortran/55574
	* gfortran.h (generate_isocbinding_symbol): New argument in prototype.
	* module.c (import_iso_c_binding_module): Update calls to
	generate_isocbinding_symbol.
	* symbol.c (gen_special_c_interop_ptr, gen_cptr_param): Ditto.
	(check_iso_c_symbol): New function.
	(generate_isocbinding_symbol): New argument 'hidden'.
	Rewrite existing symbol lookup.  Avoid namespace pollution if 'hidden'
	is set.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr55574_v20-4.patch
Type: text/x-diff
Size: 7962 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20130302/77a5296b/attachment.bin>
-------------- next part --------------
2013-03-02  Mikael Morin  <mikael@gcc.gnu.org>

	PR fortran/55574
	* gfortran.dg/iso_c_binding_only_2.f03: New test.
-------------- next part --------------
! { dg-do compile }
!
! PR fortran/55574
! The following code used to be accepted because C_LOC pulls in C_PTR
! implicitly.
!
! Contributed by Valery Weber <valeryweber@hotmail.com>
!
program aaaa
  use iso_c_binding, only : c_loc
  integer, target :: i
  type(C_PTR) :: f_ptr ! { dg-error "being used before it is defined" }
  f_ptr=c_loc(i)  ! { dg-error "Can't convert" }
end program aaaa


More information about the Fortran mailing list