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

Compiler Bug: cmplx does not handle Y argument correctly

emilybo
New User
397 Views

The following is a reproducer for the problem:

 

module intel_bug

implicit none

contains

subroutine to_complex(arr, Out_1, Out_2)
integer(8), intent(in) :: arr(0:)
complex(4), intent(out) :: Out_1
complex(4), intent(out) :: Out_2

complex(4), allocatable :: a(:)

allocate(a(0:size(arr, kind=8) - 1_8))
a = cmplx(arr, 0, kind=4) ! <----------- Problematic line v1
!a = cmplx(arr, 0.0, kind=4) ! <----------- Problematic line v2
!a = cmplx(arr, kind=4) ! <----------- Problematic line fix

Out_1 = a(0_8)
Out_2 = a(1_8)

end subroutine to_complex

end module intel_bug
program my_prog

use intel_bug

integer(8), allocatable :: arr(:)
complex(4) :: test1
complex(4) :: test2

allocate(arr(0:9))

do i=0,9
arr(i) = i
end do

call to_complex(arr, test1, test2)

print *, test1, test2

end program my_prog

 

 

The output of the code is:

 

# v1
(0.0000000E+00,0.0000000E+00) (0.0000000E+00,0.0000000E+00)

# v2
(0.0000000E+00,0.0000000E+00) (0.0000000E+00,0.0000000E+00)

# v3
(0.0000000E+00,0.0000000E+00) (1.000000,0.0000000E+00)

 

 

The standard says:

CMPLX (X [, Y, KIND])

Y (optional)    shall be of type integer or real, or a boz-literal-constant. If X is of type
complex, Y shall not be present, nor shall Y be associated with an optional
dummy argument.
If Y is absent and X is not complex, it is as if Y were present with the value
zero

 

This post may be related: https://community.intel.com/t5/Intel-Fortran-Compiler/ifort-and-ifx-internal-compiler-error/m-p/1620305

 

Compiler version information:

ifx (IFX) 2024.2.1 20240711
Copyright (C) 1985-2024 Intel Corporation. All rights reserved.

1 Solution
Ron_Green
Moderator
320 Views

We did see the earlier issue.  and we fixed it an it's in the upcoming v2025.0 ifx compiler.  Output matches NAG and Gfortran for cmplx and follows the standard. 

 

$ ifx -what -V cmplx_v1.f90 && ./a.out
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2025.0.0 Build 20240930
Copyright (C) 1985-2024 Intel Corporation. All rights reserved.
 Intel(R) Fortran 25.0-1205
GNU ld version 2.41-34.fc40
 (0.0000000E+00,0.0000000E+00) (1.000000,0.0000000E+00)

$ ifx -what -V cmplx_v2.f90 && ./a.out
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2025.0.0 Build 20240930
Copyright (C) 1985-2024 Intel Corporation. All rights reserved.
 Intel(R) Fortran 25.0-1205
GNU ld version 2.41-34.fc40
 (0.0000000E+00,0.0000000E+00) (1.000000,0.0000000E+00)

$ ifx -what -V cmplx_v3.f90 && ./a.out
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2025.0.0 Build 20240930
Copyright (C) 1985-2024 Intel Corporation. All rights reserved.
 Intel(R) Fortran 25.0-1205
GNU ld version 2.41-34.fc40
 (0.0000000E+00,0.0000000E+00) (1.000000,0.0000000E+00)

View solution in original post

0 Kudos
1 Reply
Ron_Green
Moderator
321 Views

We did see the earlier issue.  and we fixed it an it's in the upcoming v2025.0 ifx compiler.  Output matches NAG and Gfortran for cmplx and follows the standard. 

 

$ ifx -what -V cmplx_v1.f90 && ./a.out
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2025.0.0 Build 20240930
Copyright (C) 1985-2024 Intel Corporation. All rights reserved.
 Intel(R) Fortran 25.0-1205
GNU ld version 2.41-34.fc40
 (0.0000000E+00,0.0000000E+00) (1.000000,0.0000000E+00)

$ ifx -what -V cmplx_v2.f90 && ./a.out
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2025.0.0 Build 20240930
Copyright (C) 1985-2024 Intel Corporation. All rights reserved.
 Intel(R) Fortran 25.0-1205
GNU ld version 2.41-34.fc40
 (0.0000000E+00,0.0000000E+00) (1.000000,0.0000000E+00)

$ ifx -what -V cmplx_v3.f90 && ./a.out
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2025.0.0 Build 20240930
Copyright (C) 1985-2024 Intel Corporation. All rights reserved.
 Intel(R) Fortran 25.0-1205
GNU ld version 2.41-34.fc40
 (0.0000000E+00,0.0000000E+00) (1.000000,0.0000000E+00)
0 Kudos
Reply