Bug 44155 - gfortran segmentation fault using iso_c_binding
Summary: gfortran segmentation fault using iso_c_binding
Status: RESOLVED DUPLICATE of bug 40963
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2010-05-16 05:12 UTC by Steve Whalen
Modified: 2010-05-16 20:24 UTC (History)
2 users (show)

See Also:
Host: x86_64-unknown-linux-gnu
Target: x86_64-unknown-linux-gnu
Build: x86_64-unknown-linux-gnu
Known to work:
Known to fail: 4.4.4 4.5.1 4.6.0
Last reconfirmed: 2010-05-16 06:58:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Whalen 2010-05-16 05:12:49 UTC
gfortran encounters a segfault when trying to compile a standalone file. The source file itself appears at the end of this comment. But first, the gfortran behavior

users/whalen> gfortran -v -save-temps test.f90
Driving: gfortran -v -save-temps test.f90 -lgfortran -lm -shared-libgcc
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=gcc/dev/20100515/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.6.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../../src/gcc-dev/configure --prefix=gcc/dev/20100515/ --with-gmp=gmp/4.3.2/ --with-mpfr=mpfr/2.4.2/ --with-mpc=mpc/0.8.1/ --with-ppl=ppl/0.10.2/ --with-cloog=cloog/0.15.9/ --enable-languages=fortran,c,c++ --enable-lto --with-libelf=libelf/0.8.13
Thread model: posix
gcc version 4.6.0 20100516 (experimental) [trunk revision 159450] (GCC) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 gcc/dev/20100515/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.6.0/f951 test.f90 -quiet -dumpbase test.f90 -mtune=generic -march=x86-64 -auxbase test -version -fintrinsic-modules-path gcc/dev/20100515/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/finclude -o test.s
GNU Fortran (GCC) version 4.6.0 20100516 (experimental) [trunk revision 159450] (x86_64-unknown-linux-gnu)
	compiled by GNU C version 4.6.0 20100516 (experimental) [trunk revision 159450], GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
GNU Fortran (GCC) version 4.6.0 20100516 (experimental) [trunk revision 159450] (x86_64-unknown-linux-gnu)
	compiled by GNU C version 4.6.0 20100516 (experimental) [trunk revision 159450], GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
test.f90: In function ‘tetgenf’:
test.f90:125:0: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.


users/whalen> cat test.f90
module mod_tetgen

  use iso_c_binding

  implicit none

  type tetgenpolygon
     logical :: initialized = .false.
     integer :: numberofvertices = 0
     integer, pointer :: vertexlist(:)
  end type tetgenpolygon

  type tetgenfacet
     logical :: initialized = .false.
     integer :: numberofpolygons = 0
     type(tetgenpolygon), pointer :: polygonlist(:)
     integer :: numberofholes = 0
     double precision, pointer :: holelist(:,:)
  end type tetgenfacet

  type tetgenio
     logical :: initialized = .false.
     integer :: handle = -1
     integer :: numberofpoints = 0
     double precision, pointer :: pointlist(:,:)
     integer :: numberoffacets = 0
     type(tetgenfacet), pointer :: facetlist(:)
     integer,           pointer :: facetmarkerlist(:)
  end type tetgenio

  interface
     subroutine tetcall &
          (inhandle, outhandle, numberofpoints, pointlist, &
          numberoffacets, numberofpolygons, numberofholes, &
          facetmarkerlist, vertexliststarts, vertexlistvals, &
          numberofoutpoints, outpointlist, numberofoutfacets) &
          bind(c)
       use iso_c_binding
       implicit none
       integer(c_int), value :: inhandle
       integer(c_int), value :: outhandle
       integer(c_int), value :: numberofpoints
       type(c_ptr), value    :: pointlist
       integer(c_int), value :: numberoffacets
       type(c_ptr), value    :: numberofpolygons
       type(c_ptr), value    :: numberofholes
       type(c_ptr), value    :: facetmarkerlist
       type(c_ptr), value    :: vertexliststarts, vertexlistvals
       integer(c_int)        :: numberofoutpoints
       type(c_ptr)           :: outpointlist
       integer(c_int)        :: numberofoutfacets
     end subroutine tetcall
  end interface

contains

  subroutine tetgenf( in, out )

    implicit none

    !-- Transferred variables
    type(tetgenio), target, intent(in)    :: in
    type(tetgenio), target, intent(inout) :: out

    !-- Local variables
    integer ppos, vpos
    integer f, p, v
    type(tetgenfacet),   pointer :: pfacet
    type(tetgenpolygon), pointer :: ppoly
    integer, allocatable, target :: npolylist(:), nholelist(:)
    integer, allocatable, target :: vertexliststarts(:), vertexlistvals(:)
    integer inhandle, outhandle
    type(c_ptr) c_outpointlist

    allocate(npolylist(in%numberoffacets))
    allocate(nholelist(in%numberoffacets))

    ppos = 1
    vpos = 1

    do f = 1, in%numberoffacets
       pfacet => in%facetlist(f)
       do p = 1, pfacet%numberofpolygons
          ppoly => pfacet%polygonlist(p)
          do v = 1, ppoly%numberofvertices
             vpos = vpos + 1
          end do
          ppos = ppos + 1
       end do
    end do

    allocate(vertexliststarts(ppos), vertexlistvals(vpos-1))

    ppos = 1
    vpos = 1

    do f = 1, in%numberoffacets
       pfacet => in%facetlist(f)
       npolylist(f) = pfacet%numberofpolygons
       nholelist(f) = pfacet%numberofholes
       do p = 1, pfacet%numberofpolygons
          vertexliststarts(ppos) = vpos
          ppoly => pfacet%polygonlist(p)
          do v = 1, ppoly%numberofvertices
             vertexlistvals(vpos) = ppoly%vertexlist(v)
             vpos = vpos + 1
          end do
          ppos = ppos + 1
       end do
    end do

    vertexliststarts(ppos) = vpos

    call tetnew(inhandle)
    call tetnew(outhandle)
    call tetcall(inhandle, outhandle,     &
         in%numberofpoints,  &
         c_loc(in%pointlist), &
         in%numberoffacets,  &
         c_loc(npolylist),   &
         c_loc(nholelist),          &
         c_loc(in%facetmarkerlist), &
         c_loc(vertexliststarts), c_loc(vertexlistvals), &
         out%numberofpoints, c_outpointlist, &
         out%numberoffacets)

    call tetfree(inhandle)

    out%initialized = .true.
    out%handle = outhandle
    call c_f_pointer(cptr=c_outpointlist, fptr=out%pointlist, &
         shape=(/ 3, out%numberofpoints /))

    deallocate(vertexliststarts, vertexlistvals)
    deallocate(npolylist, nholelist)

  end subroutine tetgenf


end module mod_tetgen
Comment 1 Joost VandeVondele 2010-05-16 06:57:59 UTC
reduced testcase:

module mod_tetgen
  use iso_c_binding
  type tetgenio
     double precision, pointer :: pointlist(:,:)
     integer :: numberoffacets = 0
  end type tetgenio
contains
  subroutine tetgenf( in, out )
    type(tetgenio), target, intent(in)    :: in
    type(tetgenio), target, intent(inout) :: out
    call tetcall(inhandle, outhandle,     &
         c_loc(in%pointlist), &
         out%numberoffacets)
  end subroutine tetgenf
end module mod_tetgen

#0  0x000000000056f9eb in gfc_conv_procedure_call (se=0x7fff0f31c1a0, sym=0x13f0400, arg=0x13f3f10, expr=0x13f44b0, append_args=0x0) at /data03/vondele/gcc_trunk/gcc/gcc/fortran/trans-expr.c:2545
#1  0x00000000005702ba in gfc_conv_function_expr (se=0x7fff0f31c1a0, expr=0x13f44b0) at /data03/vondele/gcc_trunk/gcc/gcc/fortran/trans-expr.c:3792
#2  0x000000000056a798 in gfc_conv_expr_reference (se=0x13f40f0, expr=0x13f0400) at /data03/vondele/gcc_trunk/gcc/gcc/fortran/trans-expr.c:4582
#3  0x000000000056ed56 in gfc_conv_procedure_call (se=0x7fff0f31c830, sym=0x13f38e0, arg=0x13f3850, expr=0x0, append_args=0x0) at /data03/vondele/gcc_trunk/gcc/gcc/fortran/trans-expr.c:2858
#4  0x000000000058b9f3 in gfc_trans_call (code=0x13f4990, dependency_check=0 '\0', mask=0x0, count1=0x0, invert=0 '\0') at /data03/vondele/gcc_trunk/gcc/gcc/fortran/trans-stmt.c:378
#5  0x000000000054864f in trans_code (code=0x13f4990, cond=0x0) at /data03/vondele/gcc_trunk/gcc/gcc/fortran/trans.c:1144
#6  0x00000000005624c7 in gfc_generate_function_code (ns=0x13f2740) at /data03/vondele/gcc_trunk/gcc/gcc/fortran/trans-decl.c:4456
#7  0x0000000000547c3a in gfc_generate_module_code (ns=0x13e5530) at /data03/vondele/gcc_trunk/gcc/gcc/fortran/trans.c:1392
#8  0x000000000050d45c in gfc_parse_file () at /data03/vondele/gcc_trunk/gcc/gcc/fortran/parse.c:4303
#9  0x0000000000544f7d in gfc_be_parse_file (set_yydebug=<value optimized out>) at /data03/vondele/gcc_trunk/gcc/gcc/fortran/f95-lang.c:239
Comment 2 Daniel Franke 2010-05-16 20:24:58 UTC

*** This bug has been marked as a duplicate of 40963 ***