Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
8 Views

SegFault with REAL128 conversion

The following code

PROGRAM test_stuff
  USE, INTRINSIC :: ISO_FORTRAN_ENV
  
  IMPLICIT NONE

  INTEGER(KIND=INT8) :: ivar1
  REAL(KIND=REAL128) :: rvar1
  
  PRINT *,"real128: ", real128
  ivar1 = 9
  rvar1 = cnv_real128(ivar1)
  
  CONTAINS
  
  FUNCTION cnv_real128(icls) RESULT(out)
    CLASS(*), INTENT(IN)  :: icls
    REAL(KIND=REAL128), ALLOCATABLE :: out
    ALLOCATE(out)
    SELECT TYPE(icls)
        TYPE IS (INTEGER(KIND=INT8))
        out = REAL(icls, KIND=REAL128)
      CLASS DEFAULT
        out = REAL(0.0,KIND=REAL128)
    END SELECT
  END FUNCTION cnv_real128
END PROGRAM test_stuff

gives me a segmentation fault at runtime. Replacing REAL128 with REAL64 gives me no error. I've tried with ifort-16.0 and 17.0. Is this somehow expected?

Thanks in advance!

0 Kudos
2 Replies
Highlighted
8 Views

Try attributing out with 16

Try attributing out with 16 byte alignment.

 !DIR$ ATTRIBUTES ALIGN: 16 :: out

Jim Dempsey

0 Kudos
Highlighted
8 Views

The problem is caused by the

The problem is caused by the function result being ALLOCATABLE and REAL128 - something is going very wrong there and I'll create a bug report for it. If OUT is not ALLOCATABLE, it works fine. Issue ID is DPD200415360.

Retired 12/31/2016
0 Kudos