[PATCH] D120460: [flang] Fix lowering OpenMP/OpenACC declarative constructs in non-module unit

Peixin Qiao via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 26 02:15:14 PST 2022


peixin added a comment.

In D120460#3347185 <https://reviews.llvm.org/D120460#3347185>, @kiranchandramohan wrote:

> Can you check why the patch application fails?

This is based on D120459 <https://reviews.llvm.org/D120459>. I had thought the whole file will be applied when applying the patch in Phabricator. I need to rebase this after D120459 <https://reviews.llvm.org/D120459>. Maybe I can merge them if it is easy for review?



================
Comment at: flang/lib/Lower/PFTBuilder.cpp:321
     if constexpr (lower::pft::isDeclConstruct<A>) {
-      popEvaluationList();
-      pftParentStack.pop_back();
-      constructAndDirectiveStack.pop_back();
-      popEvaluationList();
+      if (pftParentStack.back().getIf<lower::pft::ModuleLikeUnit>()) {
+        popEvaluationList();
----------------
kiranchandramohan wrote:
> What happens without this code?
This function `enterConstructOrDirective` is called by main program unit, module procedure, internal procedure, external procedure. Only to pop the evalutionlist when entering the module procedure unit since the evalutionlist stack must be empty for OpenMP/OpenACC declarative directives when calling `enterFunction`. Check https://github.com/llvm/llvm-project/blob/f3480390be614604907be447afa3f5ab10b97d04/flang/lib/Lower/PFTBuilder.cpp#L245-L286.

To be more clear, there are two cases need to be noticed:
```
$ cat file1.f90
module m
  integer x
  !$omp threadprivate(x)
end module
$ cat file2.f90
module m
  integer x
  !$omp threadprivate(x)
contains
  subroutine sub()
  end
end module
```

For `file1.f90`, just need to process the evalutionlist as if it is used in main program unit or internal procedure and the evalutionlist is popped when ending the module. For `file2.f90`, the evalutionlist cannot be popped when ending the module. Instead, need to pop it before entering the subroutine `sub`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120460/new/

https://reviews.llvm.org/D120460



More information about the llvm-commits mailing list