Fetch FGSL (0.7) from http://www.lrz-muenchen.de/services/software/mathematik/gsl/fortran/ Run ./configure --f90 gfortran && make This should compile the library successfully. Run now the following test case; result: test.f90:39: internal compiler error: Segmentation fault ==2416== Invalid read of size 8 ==2416== at 0x49F45A: gfc_conv_initializer (trans-expr.c:2832) ==2416== by 0x49F271: gfc_conv_structure (trans-expr.c:3194) ==2416== by 0x49F4DE: gfc_conv_initializer (trans-expr.c:2854) module tmod use fgsl implicit none contains subroutine expb_df() bind(c) type(fgsl_vector) :: f_x real(fgsl_double), pointer :: p_x(:) integer :: status status = fgsl_vector_align(p_x, f_x) end subroutine expb_df end module tmod
Created attachment 14192 [details] Test case Reduced test case. ==3237== Invalid read of size 8 ==3237== at 0x49F45A: gfc_conv_initializer (trans-expr.c:2832) ==3237== by 0x49F271: gfc_conv_structure (trans-expr.c:3194) ==3237== by 0x49F4DE: gfc_conv_initializer (trans-expr.c:2854) ==3237== by 0x496406: gfc_get_symbol_decl (trans-decl.c:1046) ==3237== by 0x4968D7: generate_local_decl (trans-decl.c:2977) ==3237== by 0x46CA26: traverse_ns (symbol.c:2930) ==3237== by 0x46CA0C: traverse_ns (symbol.c:2933)
If I remove the default initializer in type(c_ptr) :: gsl_vector = c_null_ptr the crash is gone.
gfc_conv_initializer contains: if (expr != NULL && expr->ts.type == BT_DERIVED && expr->ts.is_iso_c && expr->ts.derived && (expr->symtree->n.sym->intmod_sym_id == ISOCBINDING_NULL_PTR || expr->symtree->n.sym->intmod_sym_id == ISOCBINDING_NULL_FUNPTR)) And here: expr->symtree == NULL ...
(In reply to comment #3) > gfc_conv_initializer contains: > > if (expr != NULL && expr->ts.type == BT_DERIVED > && expr->ts.is_iso_c && expr->ts.derived > && (expr->symtree->n.sym->intmod_sym_id == ISOCBINDING_NULL_PTR > || expr->symtree->n.sym->intmod_sym_id == ISOCBINDING_NULL_FUNPTR)) > > And here: expr->symtree == NULL ... > This is a bug with iso_c_binding. The symtree is not always built for an expression. However, the expr->ts.derived is available. I have a patch that seems to fix this and I hope to submit it soon.
Subject: Bug number PR 33395 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-09/msg01018.html
Subject: Bug 33395 Author: burnus Date: Wed Sep 12 07:56:07 2007 New Revision: 128418 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128418 Log: 2007-09-12 Christopher D. Rickett <crickett@lanl.gov> PR fortran/33395 * trans-expr.c (gfc_conv_initializer): Remove unnecessary test for intmod_sym_id and use derived symbol to set new kind of C_NULL_PTR and C_NULL_FUNPTR expressions. 2007-09-12 Christopher D. Rickett <crickett@lanl.gov> PR fortran/33395 * gfortran.dg/c_ptr_tests_12.f03: New test case. Added: trunk/gcc/testsuite/gfortran.dg/c_ptr_tests_12.f03 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/trans-expr.c trunk/gcc/testsuite/ChangeLog
FIXED. (The FGSL test suite still fails due to the broken formatted read of a line ending without line break, see PR 33400; working around that bug, the test suite succeeds - hooray!)