aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher D. Rickett <crickett@lanl.gov>2007-09-12 07:56:07 +0000
committerTobias Burnus <burnus@gcc.gnu.org>2007-09-12 09:56:07 +0200
commit3e708b2571e01c269d8eabfc9c741e00a3f89603 (patch)
treec08d56c1c4b10466bb44edd3a378a4f4257c2da0
parent54a5b59be2162d982b5cf3f4a46d962c041b9e11 (diff)
downloadgcc-3e708b2571e01c269d8eabfc9c741e00a3f89603.zip
gcc-3e708b2571e01c269d8eabfc9c741e00a3f89603.tar.gz
gcc-3e708b2571e01c269d8eabfc9c741e00a3f89603.tar.bz2
re PR fortran/33395 ([ISO_C_BINDING ?] ICE (segfault) in gfc_conv_initializer)
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. From-SVN: r128418
-rw-r--r--gcc/fortran/ChangeLog7
-rw-r--r--gcc/fortran/trans-expr.c18
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gfortran.dg/c_ptr_tests_12.f0345
4 files changed, 71 insertions, 4 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 99c13c6..c17cac4 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,10 @@
+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-11 Christopher D. Rickett <crickett@lanl.gov>
PR fortran/33040
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 1a4f424..7e71a72 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 894533a..dc18e62 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2007-09-12 Christopher D. Rickett <crickett@lanl.gov>
+
+ PR fortran/33395
+ * gfortran.dg/c_ptr_tests_12.f03: New test case.
+
2007-09-12 Dorit Nuzman <dorit@il.ibm.com>
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 0000000..71e8170
--- /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" } }
+