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

An example triggers a bug on ifort/ifx

zoziha
Novice
735 Views

Here's an example of my library that uses `submodule` and `module procedure` functionality, it compiles on `gfortran`, but `ifort/ifx` reports an error, which should be a bug:

module math
    interface cross_product
        pure module function cross_product_real_kind(v1, v2)
            real(kind=4), intent(in) :: v1(3)
            real(kind=4), intent(in) :: v2(3)
            real(kind=4) :: cross_product_real_kind(3)
        end function cross_product_real_kind
    end interface
end module math
submodule(math) math_cross_product
contains
    module procedure cross_product_real_kind
        cross_product_real_kind(1) = v1(2)*v2(3) - v1(3)*v2(2)
        cross_product_real_kind(2) = v1(3)*v2(1) - v1(1)*v2(3)
        cross_product_real_kind(3) = v1(1)*v2(2) - v1(2)*v2(1)
    end procedure cross_product_real_kind
end submodule math_cross_product
> ifort -c math.f90 -o math.f90.o
math.f90(13): error #6072: A dummy argument of a statement function must be a scalar identifier.   [1]
        cross_product_real_kind(1) = v1(2)*v2(3) - v1(3)*v2(2)
--------------------------------^
math.f90(14): error #6432: This statement function has been defined more than once.   [CROSS_PRODUCT_REAL_KIND]
        cross_product_real_kind(2) = v1(3)*v2(1) - v1(1)*v2(3)
--------^
math.f90(14): error #6072: A dummy argument of a statement function must be a scalar identifier.   [2]
        cross_product_real_kind(2) = v1(3)*v2(1) - v1(1)*v2(3)
--------------------------------^
math.f90(15): error #6072: A dummy argument of a statement function must be a scalar identifier.   [3]
        cross_product_real_kind(3) = v1(1)*v2(2) - v1(2)*v2(1)
--------------------------------^
math.f90: warning #6178: The return value of this FUNCTION has not been defined.   [CROSS_PRODUCT_REAL_KIND]
math.f90(13): remark #7713: This statement function has not been used.   [CROSS_PRODUCT_REAL_KIND]
        cross_product_real_kind(1) = v1(2)*v2(3) - v1(3)*v2(2)
--------^
compilation aborted for math.f90 (code 1)
> ifort -v
ifort version 2021.9.0
> ifx -v
ifx version 2023.1.0

When I use the custom `ans` as the return value, everything works:

module math
    interface cross_product
        pure module function cross_product_real_kind(v1, v2) result(ans)
            real(kind=4), intent(in) :: v1(3)
            real(kind=4), intent(in) :: v2(3)
            real(kind=4) :: ans(3)
        end function cross_product_real_kind
    end interface
end module math
submodule(math) math_cross_product
contains
    module procedure cross_product_real_kind
        ans(1) = v1(2)*v2(3) - v1(3)*v2(2)
        ans(2) = v1(3)*v2(1) - v1(1)*v2(3)
        ans(3) = v1(1)*v2(2) - v1(2)*v2(1)
    end procedure cross_product_real_kind
end submodule math_cross_product

 

1 Reply
Barbara_P_Intel
Employee
684 Views

Thanks for reporting this issue. I filed a bug, CMPLRLLVM-46801. I'll post when it's fixed.

It's good you have a simple workaround!



0 Kudos
Reply