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

Dummy procedure pointer in pure function with intent(in) attribute raise compile-time error

s12
Novice
406 Views

Assume the following example: 

PROGRAM main
    IMPLICIT NONE

    INTEGER :: res
    INTEGER :: val = 10

    res = func1(val, func)
    CALL sub1(val, func)

CONTAINS

    PURE FUNCTION func(a)
        IMPLICIT NONE
        INTEGER :: func
        INTEGER, INTENT(IN) :: a
        func = a + 1
    END FUNCTION func

    PURE FUNCTION func1(a, ptr)
        IMPLICIT NONE
        INTEGER :: func1
        INTEGER, INTENT(IN) :: a
        PROCEDURE(func),POINTER, INTENT(IN) :: ptr
        func1 = func2(a, ptr)   !! Compile-time error: ptr: #6780: A dummy argument with the INTENT(IN) attribute shall not be defined nor become undefined.
    END FUNCTION func1

    PURE FUNCTION func2(b, ptr)
        IMPLICIT NONE
        INTEGER :: func2
        INTEGER, INTENT(IN) :: b
        PROCEDURE(func), POINTER, INTENT(IN) :: ptr
        func2 = ptr(b)
    END FUNCTION func2

    PURE SUBROUTINE sub1(a, ptr)
        IMPLICIT NONE
        INTEGER, INTENT(INOUT) :: a
        PROCEDURE(func),POINTER, INTENT(IN) :: ptr
        CALL sub2(a, ptr) !! All right.
    END SUBROUTINE sub1

    PURE SUBROUTINE sub2(b, ptr)
        IMPLICIT NONE
        INTEGER, INTENT(INOUT) :: b
        PROCEDURE(func), POINTER, INTENT(IN) :: ptr

        b = ptr(b)
    END SUBROUTINE sub2

END PROGRAM main

The call to sub2 in sub1 triggers nothing while compile-time error raised in its corresponding function version. so what's the difference ?

Labels (1)
6 Replies
Ron_Green
Moderator
394 Views

seems gfortran does not like the calls in the main program:

 

gfortran repro2.f90

repro2.f90:7:21:

 

    7 |     res = func1(val, func)

      |                     1

Error: Expected a procedure pointer for argument ‘ptr’ at (1)

repro2.f90:8:19:

 

    8 |     CALL sub1(val, func)

      |                   1

Error: Expected a procedure pointer for argument ‘ptr’ at (1)

0 Kudos
s12
Novice
369 Views
Yes gfortran complains, but with ifort/ifx, it says nothing when actual argument of the corresponding dummy procedure is not a pointer.
The usage of ptr as actual argument to func2 in func1 doesn't imply any modification but the error message said so.
0 Kudos
FortranFan
Honored Contributor II
348 Views

@s12 wrote:

.. what's the difference ?


A compiler bug, hopefully the Intel Support team will file an incident report for you.

In the meantime, see if you can manage without the "pointer" and "intent(in)" on the procedure argument and do with a more straightforward alternative that is similar to the Fortran "classic" EXTERNAL argument but with an explicit interface:

PROGRAM main
    IMPLICIT NONE

    INTEGER :: res
    INTEGER :: val = 10

    res = func1(val, func)
    CALL sub1(val, func)

CONTAINS

    PURE FUNCTION func(a)
        IMPLICIT NONE
        INTEGER :: func
        INTEGER, INTENT(IN) :: a
        func = a + 1
    END FUNCTION func

    PURE FUNCTION func1(a, ptr)
        IMPLICIT NONE
        INTEGER :: func1
        INTEGER, INTENT(IN) :: a
        PROCEDURE(func) :: ptr
        func1 = func2(a, ptr)
    END FUNCTION func1

    PURE FUNCTION func2(b, ptr)
        IMPLICIT NONE
        INTEGER :: func2
        INTEGER, INTENT(IN) :: b
        PROCEDURE(func) :: ptr
        func2 = ptr(b)
    END FUNCTION func2

    PURE SUBROUTINE sub1(a, ptr)
        IMPLICIT NONE
        INTEGER, INTENT(INOUT) :: a
        PROCEDURE(func) :: ptr
        CALL sub2(a, ptr) !! All right.
    END SUBROUTINE sub1

    PURE SUBROUTINE sub2(b, ptr)
        IMPLICIT NONE
        INTEGER, INTENT(INOUT) :: b
        PROCEDURE(func) :: ptr

        b = ptr(b)
    END SUBROUTINE sub2

END PROGRAM main

 

s12
Novice
337 Views
Thanks to you, Ron and FortranFan. The "classic" alternative works for me. Anyway, hope it'll be fixed soon.
0 Kudos
Barbara_P_Intel
Moderator
291 Views

Thank you for reporting this, @s12. I filed a bug report, CMPLRLLVM-56500. I'll let you know when it's fixed.

Thank you, @FortranFan, for the workaround.

Another workaround is to remove the PURE attribute from FUNCTION func1.



0 Kudos
s12
Novice
263 Views
0 Kudos
Reply