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

Kareem Ergawy via flang-commits flang-commits at lists.llvm.org
Thu Feb 5 01:22:46 PST 2026


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

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

>From 001238c944f6e1a0361b76b39ef619480fc56428 Mon Sep 17 00:00:00 2001
From: ergawy <kareem.ergawy at amd.com>
Date: Thu, 5 Feb 2026 02:52:47 -0600
Subject: [PATCH] [flang][OpenMP] Attach compiler-emitted mappers to arrays of
 records

Extends support for compiler-defined declare mappers for records. This
fixes a bug where arrays of records that have allocatable fields were
mapped incorrectly.
---
 flang/lib/Lower/OpenMP/OpenMP.cpp          |  3 ++-
 flang/test/Lower/OpenMP/declare-mapper.f90 | 29 ++++++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)

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



More information about the flang-commits mailing list