Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28991 Discussions

Strange segfault with OpenMP and iso_c_binding

Lars_Pastewka
Beginner
958 Views

Dear community,

I encountered weird behavior which may be a compiler bug. The following code segfaults if compiled with "-openmp".

[fortran]

module test_mod

  type test2_t

    integer :: f = 3

  endtype test2_t

  type test_t

    type(test2_t), allocatable :: a

  endtype test_t

contains

  subroutine test_func(test_cptr) bind(C)

    use, intrinsic :: iso_c_binding

    type(C_PTR), value :: test_cptr

    type(test_t), pointer :: test

    call c_f_pointer(test_cptr, test)

    if (.not. allocated(test%a)) then

      allocate(test%a)
    endif

endsubroutine

endmodule test_mod

program test_prog

  use, intrinsic :: iso_c_binding

  use test_mod

  type(test_t), target :: test

  call test_func(c_loc(test))

endprogram test_prog

[/fortran]

From the compilers I have available, the code sefaults with ifort 11.1 20101201 and 12.1.3 20120212, but does not with ifort 11.0 20081105 and ifort 12.0.0 20101116.

The code does not segfault if (all tested with ifort 12.1.3 20120212)

  • compiled without "-openmp"
  • module and program are placed in a single file
  • the "if allocated(...) then" statement is removed
  • the default value (= 3) in test2_t is removed

From debugging the code it looks like memory allocation works and the code the produces the segmentation fault when copying the default data.

Not sure what's going on here. I think it may be a compiler bug. Or is there something obvious I'm doing wrong?

Many thanks,

Lars

0 Kudos
2 Replies
Steven_L_Intel1
Employee
958 Views

I can reproduce this in versions as late as 12.1.5, but nothing more recent than that (13.0, etc.). I suspect it is a compiler bug that got fixed.

0 Kudos
Lars_Pastewka
Beginner
958 Views

Okay, thanks for that information. I see if we can update.

0 Kudos
Reply