[Bug fortran/38813] ICE with C_LOC(array)
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38813 Tobias Burnus burnus at gcc dot gnu.org changed: What|Removed |Added CC||burnus at gcc dot gnu.org --- Comment #8 from Tobias Burnus burnus at gcc dot gnu.org 2013-03-25 15:53:43 UTC --- Author: burnus Date: Mon Mar 25 15:40:26 2013 New Revision: 197053 URL: http://gcc.gnu.org/viewcvs?rev=197053root=gccview=rev Log: 2013-03-25 Tobias Burnus bur...@net-b.de PR fortran/38536 PR fortran/38813 PR fortran/38894 PR fortran/39288 PR fortran/40963 PR fortran/45824 PR fortran/47023 PR fortran/47034 PR fortran/49023 PR fortran/50269 PR fortran/50612 PR fortran/52426 PR fortran/54263 PR fortran/55343 PR fortran/55444 PR fortran/55574 PR fortran/56079 PR fortran/56378 * check.c (gfc_var_strlen): Properly handle 0-sized string. (gfc_check_c_sizeof): Use is_c_interoperable, add checks. (is_c_interoperable, gfc_check_c_associated, gfc_check_c_f_pointer, gfc_check_c_f_procpointer, gfc_check_c_funloc, gfc_check_c_loc): New functions. * expr.c (check_inquiry): Add c_sizeof, compiler_version and compiler_options. (gfc_check_pointer_assign): Refine function result check. gfortran.h (gfc_isym_id): Add GFC_ISYM_C_ASSOCIATED, GFC_ISYM_C_F_POINTER, GFC_ISYM_C_F_PROCPOINTER, GFC_ISYM_C_FUNLOC, GFC_ISYM_C_LOC. (iso_fortran_env_symbol, iso_c_binding_symbol): Handle NAMED_SUBROUTINE. (generate_isocbinding_symbol): Update prototype. (get_iso_c_sym): Remove. (gfc_isym_id_by_intmod, gfc_isym_id_by_intmod_sym): New prototypes. * intrinsic.c (gfc_intrinsic_subroutine_by_id): New function. (gfc_intrinsic_sub_interface): Use it. (add_functions, add_subroutines): Add missing C-binding intrinsics. (gfc_intrinsic_func_interface): Add special case for c_loc. gfc_isym_id_by_intmod, gfc_isym_id_by_intmod_sym): New functions. (gfc_intrinsic_func_interface, gfc_intrinsic_sub_interface): Use them. * intrinsic.h (gfc_check_c_associated, gfc_check_c_f_pointer, gfc_check_c_f_procpointer, gfc_check_c_funloc, gfc_check_c_loc, gfc_resolve_c_loc, gfc_resolve_c_funloc): New prototypes. * iresolve.c (gfc_resolve_c_loc, gfc_resolve_c_funloc): New functions. * iso-c-binding.def: Split PROCEDURE into NAMED_SUBROUTINE and NAMED_FUNCTION. * iso-fortran-env.def: Add NAMED_SUBROUTINE for completeness. * module.c (create_intrinsic_function): Support subroutines and derived-type results. (use_iso_fortran_env_module): Update calls. (import_iso_c_binding_module): Ditto; update calls to generate_isocbinding_symbol. * resolve.c (find_arglists): Skip for intrinsic symbols. (gfc_resolve_intrinsic): Find intrinsic subs via id. (is_scalar_expr_ptr, gfc_iso_c_func_interface, set_name_and_label, gfc_iso_c_sub_interface): Remove. (resolve_function, resolve_specific_s0): Remove calls to those. (resolve_structure_cons): Fix handling. * symbol.c (gen_special_c_interop_ptr): Update c_ptr/c_funptr generation. (gen_cptr_param, gen_fptr_param, gen_shape_param, build_formal_args, get_iso_c_sym): Remove. (std_for_isocbinding_symbol): Handle NAMED_SUBROUTINE. (generate_isocbinding_symbol): Support hidden symbols and using c_ptr/c_funptr symtrees for nullptr defs. * target-memory.c (gfc_target_encode_expr): Fix handling of c_ptr/c_funptr. * trans-expr.c (conv_isocbinding_procedure): Remove. (gfc_conv_procedure_call): Remove call to it. (gfc_trans_subcomponent_assign, gfc_conv_expr): Update handling of c_ptr/c_funptr. * trans-intrinsic.c (conv_isocbinding_function, conv_isocbinding_subroutine): New. (gfc_conv_intrinsic_function, gfc_conv_intrinsic_subroutine): Call them. * trans-io.c (transfer_expr): Fix handling of c_ptr/c_funptr. * trans-types.c (gfc_typenode_for_spec, gfc_get_derived_type): Ditto. (gfc_init_c_interop_kinds): Handle NAMED_SUBROUTINE. 2013-03-25 Tobias Burnus bur...@net-b.de PR fortran/38536 PR fortran/38813 PR fortran/38894 PR fortran/39288 PR fortran/40963 PR fortran/45824 PR fortran/47023 PR fortran/47034 PR fortran/49023 PR fortran/50269 PR fortran/50612 PR fortran/52426 PR fortran/54263 PR
[Bug fortran/38813] ICE with C_LOC(array)
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38813 Tobias Burnus burnus at gcc dot gnu.org changed: What|Removed |Added Status|NEW |RESOLVED Resolution||FIXED --- Comment #9 from Tobias Burnus burnus at gcc dot gnu.org 2013-03-25 17:47:30 UTC --- FIXED on the 4.9 trunk.
[Bug fortran/38813] ICE with C_LOC(array)
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38813 Salvatore Filippone sfilippone at uniroma2 dot it changed: What|Removed |Added CC||sfilippone at uniroma2 dot ||it --- Comment #6 from Salvatore Filippone sfilippone at uniroma2 dot it 2012-01-13 12:44:46 UTC --- Hello, Has this ever been resolved? I still get an ICE with a code that is essentially that of comment 1, i.e. getting the C_LOC of an allocatable component; this is true of 4.6.1 and of current trunk as of today. Interestingly, the following compiles (but I have not tried yet if it works at runtime): module foo_mod type foo_type integer, allocatable :: idx(:) end type foo_type end module foo_mod subroutine bar2(data) use foo_mod use iso_c_binding implicit none type(foo_type), intent(inout), target :: data type(c_ptr) :: cptr call getcptr(cptr,data%idx) contains subroutine getcptr(cp,v) type(c_ptr) :: cp integer, allocatable, target :: v(:) cp = c_loc(v) end subroutine getcptr end subroutine bar2 Thanks a lot Salvatore
[Bug fortran/38813] ICE with C_LOC(array)
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38813 --- Comment #7 from Salvatore Filippone sfilippone at uniroma2 dot it 2012-01-13 12:48:13 UTC --- (In reply to comment #6) And the example that still fails: -- module foo_mod type foo_type integer, allocatable :: idx(:) end type foo_type end module foo_mod subroutine bar(data) use foo_mod use iso_c_binding implicit none type(foo_type), intent(inout), target :: data type(c_ptr) :: cptr cptr = c_loc(data%idx) end subroutine bar -- [sfilippo@donald bug32]$ gfortran -v Using built-in specs. COLLECT_GCC=gfortran COLLECT_LTO_WRAPPER=/usr/local/gnu47/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../gcc/configure --prefix=/usr/local/gnu47 --enable-languages=c,c++,fortran --with-gmp=/home/travel/GNUBUILD/gmp --with-mpfr=/home/travel/GNUBUILD/mpfr --with-mpc=/home/travel/GNUBUILD/mpc Thread model: posix gcc version 4.7.0 20120110 (experimental) (GCC) [sfilippo@donald bug32]$ gfortran -c bar.f90 bar.f90: In function 'bar': bar.f90:14:0: internal compiler error: Errore di segmentazione Please submit a full bug report, with preprocessed source if appropriate. See http://gcc.gnu.org/bugs.html for instructions
[Bug fortran/38813] ICE with C_LOC(array)
--- Comment #5 from mikael at gcc dot gnu dot org 2009-01-24 22:09 --- (In reply to comment #4) This might lead to wrong code (though I don't know what f77 means for C_LOC): I think that instead of fsym-as-type one needs to go through the refs to the component and do the check ...-as there. What about setting f to true unconditionally? As C_LOC shall return a C-usable pointer, gfc_conv_array_parameter shall return a descriptorless array: we want to use the f77 calling convention anyway. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38813
[Bug fortran/38813] ICE with C_LOC(array)
--- Comment #3 from mikael at gcc dot gnu dot org 2009-01-14 20:07 --- is_scalar_expr_ptr is weird. Those are the things to change in it, IMHO: - is_scalar_expr_ptr does not need to check whether character lengths are equal to 1 as arbitrary length character variables are considered as scalars by the standard; - full arrays, (and array ranges as well) are non-scalar even if they are of size 1; - the whole reference chain should be checked, not only the last one. Hum, may be it could be reduced to a mere expr-rank == 0 ? -- mikael at gcc dot gnu dot org changed: What|Removed |Added Status|UNCONFIRMED |NEW Ever Confirmed|0 |1 Last reconfirmed|-00-00 00:00:00 |2009-01-14 20:07:58 date|| http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38813
[Bug fortran/38813] ICE with C_LOC(array)
--- Comment #4 from burnus at gcc dot gnu dot org 2009-01-14 21:26 --- @@ -2451 +2451 @@ gfc_conv_function_call (gfc_se * se, gfc -fsym-as-type != AS_ASSUMED_SHAPE; +fsym-as fsym-as-type != AS_ASSUMED_SHAPE; This might lead to wrong code (though I don't know what f77 means for C_LOC): I think that instead of fsym-as-type one needs to go through the refs to the component and do the check ...-as there. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38813
[Bug fortran/38813] ICE with C_LOC(array)
--- Comment #1 from burnus at gcc dot gnu dot org 2009-01-12 13:34 --- I think NAG f95 is right by rejecting it with: Error: line 9: The argument to C_LOC must not be an array pointer Or maybe not: 15.1.2.5 C_LOC(X) has for the result value: (2) If X is an array data entity, the result is determined as if C_PTR were a derived type containing a scalar pointer component PX of the type and type parameters of X and the pointer assignment of CPTR%PX to the first element of X were executed The example is still wrong as it fails (1c): Argument. X shall either (1) have interoperable type and type parameters and be (a) a variable that has the TARGET attribute and is interoperable, (b) an allocated allocatable variable that has the TARGET attribute and is not an array of zero size, or (c) an associated scalar pointer, or (2) be a nonpolymorphic scalar, have no length type parameters, and be Is seems as if a) no-pointer, no-allocatable arrays b) allocatable arrays (allocated without empty size) are allowed. Thus the following programs should be valid -- and it also compiles with NAG f95: use iso_c_binding implicit none type tY REAL (KIND=c_float), dimension(5) :: y_fptr = 5 REAL (KIND=c_float), dimension(:), allocatable :: y_fptr2 Integer (Kind=c_int) :: ny= 0 end type type(ty), target :: y_f type(c_ptr) :: y_cptr y_cptr = c_loc(y_f%y_fptr) allocate(y_f%y_fptr2(2)) y_cptr = c_loc(y_f%y_fptr2) end -- burnus at gcc dot gnu dot org changed: What|Removed |Added Keywords||diagnostic, ice-on-valid- ||code http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38813
[Bug fortran/38813] ICE with C_LOC(array)
--- Comment #2 from burnus at gcc dot gnu dot org 2009-01-12 16:59 --- For the diagnostics: I think it works, but we are checking in case of C_LOC(Type%Comp) the symbol Type instead of Comp. Assume that Type is a pointer and Comp is not then gfc_is_data_pointer() returns true for Type%Comp even though it is not a pointer (Type is a pointer, Type%Comp is the component of the target to which Type points). But somehow also the is_scalar_expr_ptr check and the args_sym-attr.dimension check point do something wrong. For rejects valid: Make Type a pointer and Type%Comp an array. The ICE itself is fixed by the following patch: --- trans-expr.c(Revision 143289) +++ trans-expr.c @@ -2451 +2451 @@ gfc_conv_function_call (gfc_se * se, gfc -fsym-as-type != AS_ASSUMED_SHAPE; +fsym-as fsym-as-type != AS_ASSUMED_SHAPE; -- burnus at gcc dot gnu dot org changed: What|Removed |Added Keywords||rejects-valid http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38813