From 3e708b2571e01c269d8eabfc9c741e00a3f89603 Mon Sep 17 00:00:00 2001 From: "Christopher D. Rickett" Date: Wed, 12 Sep 2007 07:56:07 +0000 Subject: [PATCH] re PR fortran/33395 ([ISO_C_BINDING ?] ICE (segfault) in gfc_conv_initializer) 2007-09-12 Christopher D. Rickett 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 PR fortran/33395 * gfortran.dg/c_ptr_tests_12.f03: New test case. From-SVN: r128418 --- gcc/fortran/ChangeLog | 7 +++ gcc/fortran/trans-expr.c | 18 ++++++-- gcc/testsuite/ChangeLog | 5 +++ gcc/testsuite/gfortran.dg/c_ptr_tests_12.f03 | 45 ++++++++++++++++++++ 4 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/c_ptr_tests_12.f03 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 99c13c6a162..c17cac4c499 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +2007-09-12 Christopher D. Rickett + + 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-11 Christopher D. Rickett PR fortran/33040 diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index 1a4f42443df..7e71a722016 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -2851,11 +2851,21 @@ gfc_conv_initializer (gfc_expr * expr, gfc_typespec * ts, tree type, if (!(expr || pointer)) return NULL_TREE; - 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)) + /* Check if we have ISOCBINDING_NULL_PTR or ISOCBINDING_NULL_FUNPTR + (these are the only two iso_c_binding derived types that can be + used as initialization expressions). If so, we need to modify + the 'expr' to be that for a (void *). */ + if (expr->ts.type == BT_DERIVED && expr->ts.is_iso_c && expr->ts.derived) + { + gfc_symbol *derived = expr->ts.derived; + expr = gfc_int_expr (0); + + /* The derived symbol has already been converted to a (void *). Use + its kind. */ + expr->ts.f90_type = derived->ts.f90_type; + expr->ts.kind = derived->ts.kind; + } if (array) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 894533aee57..dc18e62e9f7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2007-09-12 Christopher D. Rickett + + PR fortran/33395 + * gfortran.dg/c_ptr_tests_12.f03: New test case. + 2007-09-12 Dorit Nuzman PR tree-optimization/33373 diff --git a/gcc/testsuite/gfortran.dg/c_ptr_tests_12.f03 b/gcc/testsuite/gfortran.dg/c_ptr_tests_12.f03 new file mode 100644 index 00000000000..71e81709374 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/c_ptr_tests_12.f03 @@ -0,0 +1,45 @@ +! { dg-do compile } +! Verify that initialization of c_ptr components works. This is based on +! code from fgsl: +! http://www.lrz-muenchen.de/services/software/mathematik/gsl/fortran/ +! and tests PR 33395. +module fgsl + use, intrinsic :: iso_c_binding + implicit none +! +! +! Kind and length parameters are default integer +! + integer, parameter, public :: fgsl_double = c_double + +! +! Types : Array support +! + type, public :: fgsl_vector + private + type(c_ptr) :: gsl_vector = c_null_ptr + end type fgsl_vector + +contains + function fgsl_vector_align(p_x, f_x) + real(fgsl_double), pointer :: p_x(:) + type(fgsl_vector) :: f_x + integer :: fgsl_vector_align + fgsl_vector_align = 4 + end function fgsl_vector_align +end module fgsl + +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 + +! { dg-final { cleanup-modules "fgsl tmod" } } + -- 2.30.2