[flang-commits] [flang] [flang] lower ASSOCIATED for procedure pointers (PR #76067)

Yi Wu via flang-commits flang-commits at lists.llvm.org
Wed Dec 20 08:38:16 PST 2023


yi-wu-arm wrote:

Thanks for all you work! I was a bit lost when doing it, but anyways. In my local test, I test `associated` with the following code.
```fortran
MODULE func
 IMPLICIT NONE
 SAVE
 INTEGER, PARAMETER :: INT32 = SELECTED_INT_KIND(9)

 ABSTRACT INTERFACE
 FUNCTION opfn(val1, val2)
 IMPORT INT32
 INTEGER(INT32), INTENT(IN) :: val1, val2
 INTEGER(INT32) :: opfn
 END FUNCTION opfn
 END INTERFACE

 CONTAINS
 FUNCTION add(val1, val2)
 INTEGER(INT32), INTENT(IN) :: val1, val2
 INTEGER(INT32) :: add
 add = val1 + val2
 END FUNCTION add

 FUNCTION minus(val1, val2)
 INTEGER(INT32), INTENT(IN) :: val1, val2
 INTEGER(INT32) :: minus
 minus = val1 - val2
 END FUNCTION minus
END MODULE func

PROGRAM test_ptr
 USE func
 IMPLICIT NONE
 INTEGER :: temp
 PROCEDURE(opfn), POINTER :: ptr
 print *, "ptr associated on init, expect: T, actual:", associated(ptr)

 ptr => add
 PRINT *, "ptr => add, ptr(1,2):", ptr(1, 2)
 print *, "ptr associated with add, expect: T, actual:", associated(ptr,add)
 print *, "ptr not associated with minus, expect: F, actual:", associated(ptr,minus)

 ptr => NULL()
 print *, "ptr associated with NULL(), expect: F, actual:", associated(ptr)
END PROGRAM
```
The expected result is the result from gfortran, there is one of them that is particularly interesting.
gfortran:
``` 
ptr associated on init, expect: T, actual: T
 ptr => add, ptr(1,2):           3
 ptr associated with add, expect: T, actual: T
 ptr not associated with minus, expect: F, actual: F
 ptr associated with NULL(), expect: F, actual: F
```
fortran-new
```
 ptr associated on init, expect: T, actual: F
 ptr => add, ptr(1,2): 3
 ptr associated with add, expect: T, actual: T
 ptr not associated with minus, expect: F, actual: F
 ptr associated with NULL(), expect: F, actual: F
 ```
When it is initialized, should it be associated?
```fortran
 PROCEDURE(opfn), POINTER :: ptr
 print *, "ptr associated on init, expect: T, actual:", associated(ptr)
```

https://github.com/llvm/llvm-project/pull/76067


More information about the flang-commits mailing list