Strange segfault with OpenMP and iso_c_binding

Strange segfault with OpenMP and iso_c_binding

Dear community,

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

module test_mod
  type test2_t
    integer :: f = 3
  endtype test2_t
  type test_t
    type(test2_t), allocatable :: a
  endtype test_t
  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
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

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,


3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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.

Retired 12/31/2016

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

Leave a Comment

Please sign in to add a comment. Not a member? Join today