Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flang] Incorrect diagnostic on intrinsic ASSOCIATED when the TARGET argument is unlimited polymorphic #125774

Closed
DanielCChen opened this issue Feb 4, 2025 · 3 comments · Fixed by #125890
Assignees

Comments

@DanielCChen
Copy link
Contributor

Consider the following code

    type :: bType
        integer*4 :: i1
    end type

    type base
        type (bType), pointer :: b1
    end type

    class (*), allocatable, target :: x

    type (base) :: b1

    if (.not. associated (b1%b1, x)) error stop(2_4)
end

Flang currently issues an error as:

./t.f:13:15: error: Arguments of ASSOCIATED() must be a pointer and an optional valid target
      if (.not. associated (b1%b1, x)) error stop(2_4)
                ^^^^^^^^^^^^^^^^^^^^^

The code seems valid as the standard requires the type of TARGET to be compatible with POINTER argument.
Unlimited polymorphic entity is type compatible with all entities.

All ifort, gfortran and XLF compile the code successfully.

@llvmbot
Copy link
Member

llvmbot commented Feb 4, 2025

@llvm/issue-subscribers-flang-frontend

Author: Daniel Chen (DanielCChen)

Consider the following code ``` type :: bType integer*4 :: i1 end type
type base
    type (bType), pointer :: b1
end type

class (*), allocatable, target :: x

type (base) :: b1

if (.not. associated (b1%b1, x)) error stop(2_4)

end


Flang currently issues an error as:

./t.f:13:15: error: Arguments of ASSOCIATED() must be a pointer and an optional valid target
if (.not. associated (b1%b1, x)) error stop(2_4)
^^^^^^^^^^^^^^^^^^^^^


The code seems valid as the standard requires the type of `TARGET` to be compatible with `POINTER` argument.
Unlimited polymorphic entity is type compatible with all entities.

All ifort, gfortran and XLF compile the code successfully.
</details>

@klausler
Copy link
Contributor

klausler commented Feb 5, 2025

I think that this is a bug. 7.3.3 has "Even though an unlimited polymorphic entity is not considered to have a declared type, it is type compatible with all entities.", and the text defining ASSOCIATED only requires that the target be type compatible with the pointer in the case of a data pointer.

@klausler
Copy link
Contributor

klausler commented Feb 5, 2025

type t                                                                                                                                                          
end type                                                                                                                                                     
real, pointer :: rptr                                                                                                                                           
type(t), pointer :: tptr                                                                                                                                
class(*), pointer :: ulpp  
! nvfortran and cray emit no error for any of these                                                                                                                                     
print *, associated(rptr, ulpp) ! error with gfortran, ifx, nag; warning with xlf                                                                               
print *, associated(ulpp, rptr) ! error with ifx, nag; warning with xlf                                                                                         
print *, associated(tptr, ulpp) ! error with gfortran, nag; warning with xlf                                                                                    
print *, associated(ulpp, tptr) ! ok with all                                                                                                                   
print *, associated(rptr, tptr) ! not standard; error with gfortran, ifx, nag, warning with xlf                     
print *, associated(tptr, rptr) ! not standard; error with gfortran, ifx, nag, warning with xlf                                                               
end                                                                                                                                                             

I think that only the last two calls should be flagged as errors. I might emit a portability warning for the first three cases.

@klausler klausler self-assigned this Feb 5, 2025
klausler added a commit to klausler/llvm-project that referenced this issue Feb 5, 2025
As I read the standard, an unlimited polymorphic pointer or target
should be viewed as compatible with any data target or data pointer
when used in the two-argument form of the intrinsic function ASSOCIATED().

Fixes llvm#125774.
klausler added a commit that referenced this issue Feb 27, 2025
…125890)

As I read the standard, an unlimited polymorphic pointer or target
should be viewed as compatible with any data target or data pointer when
used in the two-argument form of the intrinsic function ASSOCIATED().

Fixes #125774.
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this issue Feb 27, 2025
… as error (#125890)

As I read the standard, an unlimited polymorphic pointer or target
should be viewed as compatible with any data target or data pointer when
used in the two-argument form of the intrinsic function ASSOCIATED().

Fixes llvm/llvm-project#125774.
cheezeburglar pushed a commit to cheezeburglar/llvm-project that referenced this issue Feb 28, 2025
…lvm#125890)

As I read the standard, an unlimited polymorphic pointer or target
should be viewed as compatible with any data target or data pointer when
used in the two-argument form of the intrinsic function ASSOCIATED().

Fixes llvm#125774.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants