<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/153031>153031</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[flang] Incorrectly referenced function multiple times when it is used for array indexing.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang:frontend
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
DanielCChen
</td>
</tr>
</table>
<pre>
Consider the following reducer:
```
integer :: count = 0
type dt
integer, allocatable :: i(:)
end type
type(dt) :: x(10)
integer :: ub
allocate(x(2)%i(2:3))
ub = ubound(x(foo())%i,1) !! Called twice here.
if (count /= 7) error stop 5
contains
integer function foo()
foo = 2
count = count + 1
end function
end
```
Flang called function `foo` twice when it is referenced to get the array index for `x`. The `count` should be `1`.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJxcU01vqzAQ_DXmsmpk7JDAgQNNFOnd3x8w9gJ-cuzIH23z75-WkDYqQsLGMzuzA6tSsrNH7FnzzppzpUpeQuzPylt0p9OCvhqDufen4JM1GCEvCFNwLnxaP0NEUzRGJgfGB3bg280H6zPOGIFO5AA6FJ-ByTPQYb7fEExmfADYgEycQDkXtMpqdPjkWSZaWoqO8QG9AaJuFZhoTWaie2K_mGhr_oD-ki8j2ePDpkBUQgsCi8auSznIdUv0Mq5eyxiKNxt4CoHMPCAr6VST-nYxUTNRw0k5hwbyp9UIC0bckZsJmGi3DMSFSh-JijGGCCmHGzSMDzr4rKxPr7nAVLzONnj40ecDbVaHYsXCS75PlXeo1zMK7VnjkeGvL8X4cHHKz6Af1r8F2YGT5oFv3Xwu6MFmsAkiThjRa-o0wIx5_S1UjOoO1hv8gilEKvDFDnwHfxekzWqN6qUlFGdgXN_WBHn4qEwvTSc7VWFfH5t9J_ZNx6ulN_tjK8TxOHWKG4Vt22lZazM1OB0UtofK9oKLhrd1XTdccrkzk5LtKBRqOepJGrbneFXW7Zz7uO5CnCubUsG-biSXdeXUiC6tQyDERHEwOUwx-EyBCUGjEXvivo1lTmzPnU05_VTLNrt1iB7k5gx_vA4xos7u_prXd7zX4rK9OYRsr5he0y2JcCG-Bmr9vKtKdP2S8y2tI3Fh4jLbvJRxp8OViQuZ2R5vtxj-oc5MXNY-ExOXrdWPXvwPAAD__wHnNPc">