Bug 33395 - [ISO_C_BINDING ?] ICE (segfault) in gfc_conv_initializer
Summary: [ISO_C_BINDING ?] ICE (segfault) in gfc_conv_initializer
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks: ISO_C_Binding
  Show dependency treegraph
 
Reported: 2007-09-11 16:46 UTC by Tobias Burnus
Modified: 2007-09-12 08:19 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Test case (368 bytes, text/plain)
2007-09-11 18:43 UTC, Tobias Burnus
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2007-09-11 16:46:04 UTC
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
Comment 1 Tobias Burnus 2007-09-11 18:43:51 UTC
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)
Comment 2 Tobias Burnus 2007-09-11 18:45:29 UTC
If I remove the default initializer in
     type(c_ptr) :: gsl_vector = c_null_ptr
the crash is gone.
Comment 3 Tobias Burnus 2007-09-11 19:09:35 UTC
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 ...
Comment 4 Chris Rickett 2007-09-11 19:51:03 UTC
(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.
Comment 5 patchapp@dberlin.org 2007-09-11 20:26:19 UTC
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
Comment 6 Tobias Burnus 2007-09-12 07:56:17 UTC
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

Comment 7 Tobias Burnus 2007-09-12 08:19:06 UTC
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!)