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

    <tr>
        <th>Summary</th>
        <td>
            [flang][OpenMP] Implement better FIRSTPRIVATE/LASTPRIVATE diagnostics
        </td>
    </tr>

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

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

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

<pre>
    Please consider implementing better FIRSTPRIVATE/LASTPRIVATE diagnostics based on comments in https://github.com/llvm/llvm-project/issues/143764#issuecomment-2997706215

In case Fujitsu fixes the tests mentioned in the above issue, here are their sources that caused the issue to be filed in the first place:

0521_0030.f90:
```
INTEGER :: i
i=1
i0=1
i1=1
j=2
!$OMP PARALLEL default(firstprivate)
!$OMP SECTIONS
!$OMP parallel private(i)
i=100
!$OMP END parallel
!$OMP parallel firstprivate(i0)
i0=100
!$OMP END parallel
!$OMP parallel do lastprivate(i1)
do ii=1,1
i1=100
end do
!$OMP END parallel do
!$OMP parallel shared(j)
j=200
!$OMP END parallel
!$OMP END SECTIONS
!$OMP END PARALLEL
if (i.ne.1) print *,'err var i=',i
if (i0.ne.1) print *,'err var i0=',i0
if (i1.ne.100) print *,'err var i1=',i1
if (j.ne.2) print *,'err var j=',j
print *,'pass'

END 
```

0686_0024.f90:
```
module mod0
 integer::i,ii,iii,iiii
      end module

      module mod1
 use mod0
       integer::j,jj,jjj,jjjj
       integer::k=0
      end module

      program ompv2
      use mod1
      common /com/ m,mm,mmm,mmmm

!$omp parallel num_threads(10)

!$omp do reduction(+:k),lastprivate(i,ii,iii,iiii),firstprivate(j,jj,jjj,jjjj)
 do i=1,10
      do ii=1,10
      do iii=1,10
      do iiii=1,10
 k=k+1
      enddo
      enddo
      enddo
      enddo

!$omp do reduction(+:i,ii,iii),lastprivate(j,jj,jjj,jjjj),firstprivate(m,mm,mmm,mmmm)
 do j=1,iiii-1
      do jj=1,iiii-1
      do jjj=1,iiii-1
      do jjjj=1,iiii-1
        i=i+1
        ii=ii+1
        iii=iii+1
 enddo
      enddo
      enddo
      enddo

!$omp do reduction(+:j,jj,jjj),lastprivate(m,mm,mmm,mmmm)
      do m=1,jjjj-1
 do mm=1,jjjj-1
      do mmm=1,jjjj-1
      do mmmm=1,jjjj-1
 j=j+1
        jj=jj+1
        jjj=jjj+1
      enddo
      enddo
 enddo
      enddo

!$omp end parallel
      if (k/=10000) print *,k
 if (i/=10011.or.ii/=10011.or.iii/=10011.or.iiii/=11) print *,i,ii,iii,iiii
 if (j/=10011.or.jj/=10011.or.jjj/=10011.or.jjjj/=11) print *,j,jj,jjj,jjjj
      if (m/=11.or.mm/=11.or.mmm/=11.or.mmmm/=11) print *,m,mm,mmm,mmmm

      print *,'pass'

      end
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0V99v4jgQ_mvMy2iRMwkkPPCQQjlV6u5W3epeVyYZwGkSR7ZT3f73JzshNPzo9u50CBnyjeez57Nn7Ahj5L4mWrLZHZutJ6K1B6WX1O6pJmrMwdKverJV-a_lU0nCEGSqNjInDbJqSqqotrLew5asJQ2bh-cfL0_PD3-mL_cMN4_p8AS5FPtaGSszA1thKAdVQ6Yqx2BA1nCwtjEsTBluGG720h7a7TRTFcNNWb4df740WhWUWYYbaUxLhuEmiMJ4HjEMPdJzfsHFIo75HIMZ4ynj6UMNmQtg0xbSmhZ28i8yYA8Elow14ENRNeVuMg4WW_VG4DkZruBAmkBocjapwahWZ55AWMhE6yJyXr4_WAVbgp0sT3Q7qY2FphQZuSj9nPgMg5-ch3y6W_AenfP-y9OHby_3f9w_g7OEKUjGU8nCdeB--fFP0P8pWLhGR4ABw-j71yd4Sp_Tx8f7R8hpJ9rSMkz8JBot34QlhotR9x_3q5eH799-jMBGaFGWVMLglMjO0c-E81Hv-2_rweM6zXgCieQ9Gf9XbLmCUoz4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