<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/76529>76529</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Cannot have Cray pointer to `bind(C)` object
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          eschnett
      </td>
    </tr>
</table>

<pre>
    Flang reports an error when I declare a Cray pointer to a `bind(C)` type. The error complains that the `bind(C)` does not have the `sequence` attribute. I think this is wrong; `bind(C)` types implicitly have the sequence attribute (or a very similar property), and I thus think this code should be accepted.

The failing code is:
```Fortran
module m
  implicit none

  ! Declare a type. It's a "bind(C)" type and thus cannot have the "sequence" attribute.
 type, bind(C) :: t
     integer i
  end type t

  ! Define a Cray pointer that dereferences to a value of this type.
  type(t) :: val
 integer*8 :: ptr
  pointer (ptr, val)
end module m
```

This is the error:
```
$ flang-new-mp-17 -S cray.f90
error: Semantic errors in cray.f90
./cray.f90:12:17: error: Type of Cray pointee 'val' is a non-sequence derived type
    pointer (ptr, val)
 ^^^
```

Adding the `sequence` attribute does not work because `bind(C)` types are not allowed to have this attribute, and Flang then reports an error.

FWIW GFortran accepts this code (with the `-fcray-pointer` option).

I am using `flang-new-mp` on macOS installed via MacPorts.
```
$ flang-new-mp-17 --version
flang-new version 17.0.6
Target: x86_64-apple-darwin23.2.0
Thread model: posix
InstalledDir: /opt/local/libexec/llvm-17/bin
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVU2PozgQ_TXOpQSCIoFw4NDTvaz6sNqVZqQ5rgyuBO8Ym7VN0vn3K_ORpj9mtFKEgl31_OrVK8Odk2dNVLHDF3Z42vHRd8ZW5NpOk_e7xohbVSuuz2BpMNY74BrIWmPh2pGGZxDUKm4JODxafoPBSO3JgjfAgeVJI7VgeHxkWLI8AX8bKIZvH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