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

    <tr>
        <th>Summary</th>
        <td>
            [flang] Compilation error in cray pointer
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          ohno-fj
      </td>
    </tr>
</table>

<pre>
    ```
Version of flang-new : 16.0.0(e0fb01e97b6b7d2fe66b17b36eeb98aa78c6e3bb)
```

cray pointer results in a compilation error.
GNU's Fortran compiler terminates normally with programs that use cray pointer when the option `-fcray-pointer` is used.

The following are the test program, flang-new compilation results, and gfortran compilation results.  

snggn856_.f90:
```fortran
subroutine s(i,k)
 type x
   integer,pointer::p1(:),p2(:)
 end type
 type (x),pointer:: v(:)
 integer,target::t1(3)=(/1,2,3/)
 integer,target::t2(4)=(/4,5,6,7/)
integer j(2)
 pointer(n1,d1)
 pointer(n2,d2)
 allocate(v(k))
 select case(i)
  case (1)
   allocate(v(2)%p1(2))
   v(2)%p1=(/11,12/)
   v(2)%p2=>t1(1:3:2)
end select
n1=loc(v(2)%p1)
n2=loc(v(2)%p2)
j=jfoo(v(k)%p1,v(k)%p2,n1,n2,i)+jfoo(v(k)%p1,v(k)%p2,n1,n2,i)
if (j(1)/=i*2)write(6,*) "NG"
if (j(2)/=i*2+2)write(6,*) "NG"
deallocate(v)
contains
function jfoo(i1,i2,n1,n2,i)
integer i1(2),i2(2),jfoo(2)
 pointer(n1,d1)
 pointer(n2,d2)
select case(i)
 case (1)
   if (i1(1)/=11)write(6,*) "NG"
   if (i1(2)/=12)write(6,*) "NG"
   if (i2(1)/=1)write(6,*) "NG"
   if (i2(2)/=3)write(6,*) "NG"
   if (loc(i1)/=n1)write(1,*) i,'i1 copied'
   if (loc(i2)==n2)write(1,*) i,'i2 no copied'
end select
jfoo(1)=i
jfoo(2)=i+1
end function
end
call s(1,2)
print *,'snggn856 : pass'
end
```

```
$ flang-new -flang-experimental-exec snggn856_.f90
error: Semantic errors in snggn856_.f90
./snggn856_.f90:27:13: error: 'd1' was already declared as a Cray pointee
   pointer(n1,d1)
              ^^
./snggn856_.f90:28:13: error: 'd2' was already declared as a Cray pointee
   pointer(n2,d2)
              ^^
$
```

GNU's Fortran compiler terminates normally with programs that use cray pointer when the option `-fcray-pointer` is used.  


```
$ gfortran snggn856_.f90
snggn856_.f90:9:8:

  pointer(n1,d1)
        1
Error: Cray pointer declaration at (1) requires -fcray-pointer flag
snggn856_.f90:10:8:

  pointer(n2,d2)
        1
Error: Cray pointer declaration at (1) requires -fcray-pointer flag
snggn856_.f90:27:8:

  pointer(n1,d1)
        1
Error: Cray pointer declaration at (1) requires -fcray-pointer flag
snggn856_.f90:28:8:

  pointer(n2,d2)
        1
Error: Cray pointer declaration at (1) requires -fcray-pointer flag
$
```

```
$ gfortran snggn856_.f90 -fcray-pointer
$ ./a.out
 snggn856 : pass
$
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzNV0uTmzgQ_jX4ojKFJPPwgYPHM84tl31ctwQILAcLIkQ88--3JcA8YnsmSdVupmwPkvrx9dctqUmq7C12Aq__eM-Ot_ubq0ZUElU5yksmi7XkF-TQHcKB67meQyLu5YmH-TZMgiTMSM6DIMFhQgPOk23EWBilAadJ4pBtZ3LhoftNFXtDdSWk5gop3rSlbpCQiKG0OteiZNqg4EpVyu00Pn3-yyFhgw6V0orJXg60wcJZSKZ5g2Slzqws39BF6COqVVUodm6QPjKN2oajmdfLkUtY4qiqrTNAuM6NxLqXgAkkGqOYuVPsf4JOXpVldRGyQExxawX868GlQ_YT-qYR9aEaASYzVOSzaGYyLkJTr40sChn5wT9uvvUgIwtye0O9bJuoqtVCcgSuIgHuvlzzgfRbzdFrP0DIxFpAtGQ_xA3G6a7GoGkeQQ-WyDjqFDnAN5amRkHmtZefmkLflsqjT81UwXUnp41Laq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