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

    <tr>
        <th>Summary</th>
        <td>
            [Flang] Incorrect execution result when a pointer variable of the same name is defined for each cray pointer in two dependent modules, and a different array address is defined for each pointer variable
        </td>
    </tr>

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

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

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

<pre>
    ```
Version of flang : 21.0.0(9fe6f6a0d430b872750354c20f3e4a651bd1f135)/AArch64
```

In the attached program, a pointer variable of the same name is defined for each `cray pointer` in two dependent modules (1), and a different array address is defined for each pointer variable (2).  
The execution result of such a program is incorrect.  
The value of `v1` in the main program is expected to be 1.0.

The following are the test program, Flang, Gfortran and ifx compilation/execution result.

sngg752d_2.f90:
```fortran
module m1
 implicit none
  real::v1
  pointer (ptr,v1)  ! (1)
 real::x(2)
contains
  subroutine s
    implicit none
    x=[1,2]
 ptr=loc(x)  ! (2)
  end subroutine s
end module m1

module m2
  use m1
 implicit none
  private ptr
contains
  subroutine ss
    real::v2,y(2)
 pointer (ptr,v2)  ! (1)
    dimension v2(2)
    y=[11,12]
 ptr=loc(y)  ! (2)  The address assigned to ptr changes from the address of x to the address of y.
    write(6,*) "ss : v1 = ", v1, " v2 = ", v2
 end subroutine ss
end module m2

program main
  use m2
  implicit none
 call s
  call ss
  write(6,*) "main : v1 = ", v1
  print *,'pass'
end program main
```

```
$ flang sngg752d_2.f90; ./a.out
 ss : v1 =  11. v2 =  11. 12.
 main : v1 =  -118116.53
 pass
$
```

```
$ gfortran -fcray-pointer sngg752d_2.f90; ./a.out
 ss : v1 =    1.00000000      v2 = 11.0000000       12.0000000
 main : v1 =    1.00000000
 pass
$
```

```
$ ifx sngg752d_2.f90; ./a.out
 ss : v1 =    1.000000 v2 =    11.00000       12.00000
 main : v1 =    1.000000
 pass
$
```

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVk9v47gP_TTKhagh0X8SH3LwpMgPc_9hrwvZpmMNbMmQ5DT59gvZTuu6mVnMYIOiUQiRfO9RpCSdUxdNdGTpN5a-7uToW2OPptXmpfmxK019P7KML3-8-IusU0aDaaDppL4AiwtAEfGIMzzkDWVNJnmdxLw87HGf8jhNKuRNTInMUlHWohFxyjBneC4KW7VZwnixzsB48V2Dbwmk97JqqYbBmouVPcMTSBiM0p4sXKVVsuwoQAm7newJdPinHNTUKE01NMYCyaoFlvHKyvvDm2UclAb_ZqCmgXRN2kNv6rEjBwwPYkJ4AqlrkFCrpiEbtkgbgsi6tuTc00Rf4DE8IMM8AmC8-H9LQDeqRh9EtOTGzgcCbqzawG0mGgIrXRlrqfIfjlfZjRNdlvGreFBoCXqp9NqXbgNVnmrwBkqCUJ1Z2BClMV1n3pS-gLQ0uXtyfq3xORQ2LP7XGOut1JMMqrlBZfpBdTKAZ3jeElmSOH257FOs_8aoyTmLi3WBl4iMF7Pa0AvGC1D90KlKedBGUzCAJdkF37i4TjvehWV4GLxleLqGIgEwFO8V48XK77Yoz3hRGe2l0m4K5MbSmtErTTAb4El6gBuLX1n6TTA8IUtfgzXkjV87UzE83NbJlzQApOtt_GBac11Rx8lndD9XYbDqKj1NmX9B48FjJRoyPN1X0L7Kh8_kA4Ba9aSnJg9bPrgB3BdJgibimSj3rSgA4cg9-mUZNtO5HLyFqpX6Qg4aa_q545eNpoFb2LSx3aMFyJtVnhgeMoYnhkVIxBCdm6bRVQCLX4MhnOFwSk7hB1zxk30Sf1uvbcFwLtijt0KjfdRsLt-XolWy65aTNS_n9XPMU-s-Rb2UX3uYdp8Y7gfpHMP9gnEDajNDP_3EZJnW2978BhHDs4zM6EPCzwqCENFDtWktcCrAFjO8CHEQIovSeDoQcmLM8Mlk36K6PCbMSxPG88vjlP4eTggjbvnA9FlQi3f7bA4MFsNTIutAv0slzMc_hf2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