[flang-commits] [flang] [flang][OpenMP] Attach compiler-emitted mappers to arrays of records (PR #179892)

via flang-commits flang-commits at lists.llvm.org
Thu Feb 5 01:23:23 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-openmp

Author: Kareem Ergawy (ergawy)

<details>
<summary>Changes</summary>

Extends support for compiler-defined declare mappers for records. This fixes a bug where arrays of records that have allocatable fields were mapped incorrectly.

---
Full diff: https://github.com/llvm/llvm-project/pull/179892.diff


2 Files Affected:

- (modified) flang/lib/Lower/OpenMP/OpenMP.cpp (+2-1) 
- (modified) flang/test/Lower/OpenMP/declare-mapper.f90 (+29) 


``````````diff
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index df89cbe46a5c8..614233db7afb2 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -2784,7 +2784,8 @@ genTargetOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
 
           if (!mapperIdName.empty()) {
             bool allowImplicitMapper =
-                semantics::IsAllocatableOrObjectPointer(&sym);
+                semantics::IsAllocatableOrObjectPointer(&sym) ||
+                requiresImplicitDefaultDeclareMapper(*typeSpec);
             bool hasDefaultMapper =
                 converter.getModuleOp().lookupSymbol(mapperIdName);
             if (hasDefaultMapper || allowImplicitMapper) {
diff --git a/flang/test/Lower/OpenMP/declare-mapper.f90 b/flang/test/Lower/OpenMP/declare-mapper.f90
index 7eda1a4c497be..6708872aa19ab 100644
--- a/flang/test/Lower/OpenMP/declare-mapper.f90
+++ b/flang/test/Lower/OpenMP/declare-mapper.f90
@@ -11,6 +11,7 @@
 ! RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=50 -J %t %t/omp-declare-mapper-7.use.f90 -o - | FileCheck %t/omp-declare-mapper-7.use.f90
 ! RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=50 -module-dir %t %t/omp-declare-mapper-8.mod.f90 -o - >/dev/null
 ! RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=50 -J %t %t/omp-declare-mapper-8.use.f90 -o - | FileCheck %t/omp-declare-mapper-8.use.f90
+! RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=50 -J %t %t/omp-declare-mapper-9.implicit.f90 -o - | FileCheck %t/omp-declare-mapper-9.implicit.f90
 
 !--- omp-declare-mapper-1.f90
 subroutine declare_mapper_1
@@ -360,3 +361,31 @@ program use_module_default_mapper
     a%x = 8
   !$omp end target
 end program use_module_default_mapper
+
+!--- omp-declare-mapper-9.implicit.f90
+! Verify that we emit declare mapper ops for arrays of records that are mapped
+! implicitly.
+
+! CHECK: omp.declare_mapper @[[MAPPER_NAME:.*record_with_alloc_modrecord_with_alloc_omp_default_mapper]] : !fir.type
+
+! CHECK: func.func @{{.*}}random_inputs()
+! CHECK:   %[[ARR_DECL:.*]]:2 = hlfir.declare {{.*}} {{{.*}}, uniq_name = "{{.*}}inputs"}
+! CHECK:   omp.map.info var_ptr(%[[ARR_DECL]]#1 : {{.*}}) {{.*}} mapper(@[[MAPPER_NAME]])
+! CHECK-NOT: omp.map.info
+module record_with_alloc_mod
+  implicit none
+  public :: record_with_alloc
+
+  type record_with_alloc
+    real, allocatable :: values_(:)
+  end type
+end module record_with_alloc_mod
+
+subroutine random_inputs()
+  use record_with_alloc_mod, only : record_with_alloc
+  type(record_with_alloc), target :: inputs(2)
+
+  !$omp target
+    inputs(1)%values_ = [1,2,3,4]
+  !$omp end target
+end subroutine

``````````

</details>


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


More information about the flang-commits mailing list