Found at http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/5392e4c270d4f3c7
The following program segfaults and valgrind shows: ==31102== Invalid read of size 4 ==31102== at 0x4B3E31: gfc_conv_function_call (trans-expr.c:2451) ==31102== by 0x4B448A: gfc_conv_function_expr (trans-expr.c:3345) ==31102== by 0x4B507C: gfc_trans_assignment_1 (trans-expr.c:4642) ==31102== by 0x4B520C: gfc_trans_assignment (trans-expr.c:4804) ==31102== by 0x49522F: gfc_trans_code (trans.c:1061) ==31102== by 0x4ACC5A: gfc_generate_function_code (trans-decl.c:3849) ==31102== by 0x46211B: gfc_parse_file (parse.c:3860) I think NAG f95 is right by rejecting it with: Error: line 9: The argument to C_LOC must not be an array pointer [and one needs to use as with C a pointer to the first element ("&target" or "&target[0]" not "&target[]" or something similar)]. It is accepted with ifort and g95. Relevant trans-expr.c lines: 2448 /* We should want it to do g77 calling convention. */ 2449 f = (fsym != NULL) 2450 && !(fsym->attr.pointer || fsym->attr.allocatable) 2451 && fsym->as->type != AS_ASSUMED_SHAPE; 2452 f = f || !sym->attr.always_explicit; use iso_c_binding implicit none type tY REAL (KIND=4), dimension(:),pointer :: y_fptr => NULL() Integer (Kind=4) :: ny = 0 end type type(ty), target :: y_f type(c_ptr) :: y_cptr y_cptr = c_loc(y_f%y_fptr) end -- Summary: ICE with C_LOC(array) Product: gcc Version: 4.4.0 Status: UNCONFIRMED Keywords: ice-on-invalid-code Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: burnus at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38813