This is an archive of the discontinued LLVM Phabricator instance.

[Flang][OpenMP] Use the ultimate symbol for allocatable check
ClosedPublic

Authored by kiranchandramohan on Feb 20 2023, 5:14 AM.

Diff Detail

Event Timeline

Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptFeb 20 2023, 5:14 AM
kiranchandramohan requested review of this revision.Feb 20 2023, 5:14 AM

This reminds me another case as follows:

program main
  real(4), pointer::a
  allocate(a)
  a=1.0
!$omp parallel private(a)
  if (.not. associated(a)) then
     print *,'ng1: a'
  endif
  a=2.0
!$omp end parallel
  if (a /= 1.0) then
     print *, 'ng: a = ', a
  endif
  print *,'pass'
end program main
$ flang-new -fc1 tmp.f90 -fopenmp
error: Semantic errors in tmp.f90
./tmp.f90:6:24: error: POINTER= argument of ASSOCIATED() must be a POINTER
    if (.not. associated(a)) then
                         ^
./tmp.f90:2:21: Declaration of 'a'
    real(4), pointer::a
                      ^

Since we use host-association for privitized variables, is there one better way to handle these cases? I guess there are still some bugs if we make the changes in non-OpenMP function code.

This reminds me another case as follows:

program main
  real(4), pointer::a
  allocate(a)
  a=1.0
!$omp parallel private(a)
  if (.not. associated(a)) then
     print *,'ng1: a'
  endif
  a=2.0
!$omp end parallel
  if (a /= 1.0) then
     print *, 'ng: a = ', a
  endif
  print *,'pass'
end program main
$ flang-new -fc1 tmp.f90 -fopenmp
error: Semantic errors in tmp.f90
./tmp.f90:6:24: error: POINTER= argument of ASSOCIATED() must be a POINTER
    if (.not. associated(a)) then
                         ^
./tmp.f90:2:21: Declaration of 'a'
    real(4), pointer::a
                      ^

Since we use host-association for privitized variables, is there one better way to handle these cases? I guess there are still some bugs if we make the changes in non-OpenMP function code.

Thanks @peixin, one option is to copy the attributes while making the associated symbol. But I was advised to instead use the UltimateSymbol way in https://reviews.llvm.org/D112876. I don't know of other general ways to handle these. You are right that there are some bugs. I hope we can catch these with widespread testing and careful reviews like yours. :)

Do you want me to make the change for pointer in this patch?

peixin accepted this revision.Feb 21 2023, 4:40 AM

Thanks @peixin, one option is to copy the attributes while making the associated symbol. But I was advised to instead use the UltimateSymbol way in https://reviews.llvm.org/D112876. I don't know of other general ways to handle these. You are right that there are some bugs. I hope we can catch these with widespread testing and careful reviews like yours. :)

Thanks. Got it. That fix is too long ago and I forgot about it. Now this sounds reasonable to me.

Do you want me to make the change for pointer in this patch?

You can fix it in another patch, which may look more clear. Either way is OK to me.

This revision is now accepted and ready to land.Feb 21 2023, 4:40 AM