Complex(real128) math in parameter triggers Internal Compiler Error in ifx

Stumbled upon this ICE from ifx while building the 128-bit SVD for the Fortran Standard Library:

program t
   use iso_fortran_env, only: qp => real128
   implicit none

   real(qp), parameter :: const = 2.0_qp
   complex(qp), parameter :: cone = (1.0_qp,0.0_qp)

   complex(qp), parameter ::  a = const*cone ! ifx ICE
   complex(qp), parameter ::  b = cone       ! no ICE

   print *, a

end program

The bug is caused by the 128-bit arithmetic operation (const*cone), and does not appear in case of simple assignment

You can test it here at the Compiler Explorer, hopefully it will be useful for compiler developers to deploy a fix.

I see the ICE in 2024.1 and 2024.0 ifx versions.
I just tested an early build of 2024.2, which is not public and there is no ICE.
So this bug will be fixed once 2024.2 is released, roughly early July 2024. We have reworked some of the initialization code for 2024.2, no doubt this fixed the issue.
thanks for bringing this to my attention.

3 Likes

Awesome! Thanks a lot @greenrongreen, that’s a quick fix!

Talking about complex parameters, one reason I was doing:

real(qp), parameter :: sqrt2 = sqrt(2.0_qp)
complex(qp), parameter :: csqrt2 = sqrt2*(1.0_qp,0.0_qp)

is that I was almost sure complex parameters could not be set from expression i.e. that something like this was forbidden:

complex(qp), parameter :: abc = (sqrt(1.5),tan(6.78))

I see that I was wrong. Everything works across all compilers if I replace the expression with other parameter constants:

real(qp), parameter :: s15 = sqrt(1.5)
real(qp), parameter :: t67 = tan(6.78)
complex(qp), parameter :: abc = (s15,t67)

So I’m a bit confused. What’s the rationale?

You can use the cmplx function and write

complex(qp), parameter :: abc = cmplx(sqrt(1.5), tan(6.78), kind=qp)

2 Likes

Oh, thanks @Beliavsky!

So, the limitations must have to do with the parentheses, but we can always use the intrinsic cmplx.

There is a subtle distinction, but probably irrelevant in this (and most) case.

R718 complex-literal-constant is ( real-part , imag-part )

16.9.53 CMPLX (X [, KIND]) or CMPLX (X [, Y, KIND])
Description. Conversion to complex type.