[flang-commits] [flang] [flang][openmp] Support importing module declare target globals (PR #213930)

Sergio Afonso via flang-commits flang-commits at lists.llvm.org
Tue Aug 25 05:25:47 PDT 2026


================
@@ -1510,8 +1511,10 @@ static void getDeclareTargetInfo(
     List<Clause> clauses = makeClauses(construct.v.Clauses(), semaCtx);
     if (clauses.empty()) {
       // Case: implicit capture of the enclosing function/subroutine.
+      assert(eval.has_value() &&
+             "expected eval to have value when clauses is empty");
----------------
skatrak wrote:

Is it currently guaranteed that the `declare_target` for a module global/function will always have clauses? For that to be the case, the module writer should already be making some transformations. There should probably be a unit test for this, something like:
```f90
!--- declare_target_module.f90
module declare_target_module
  contains
    subroutine fn(x)
      implicit none
      !$omp declare target
      ! Either check that it's transformed to "!$omp declare target enter(fn)"
      ! or getDeclareTargetInfo() must always get a valid eval.
      integer, intent(out) :: x
      x = 3
    end subroutine
end module

!--- use_declare_target_module.f90
program main
  use declare_target_module
  implicit none
  integer :: x
  call myf(x)
end program
```

https://github.com/llvm/llvm-project/pull/213930


More information about the flang-commits mailing list