[flang-commits] [flang] [flang][OpenMP] Prevent attaching implicit mapper to data motion clause (PR #185850)
Akash Banerjee via flang-commits
flang-commits at lists.llvm.org
Wed Mar 11 03:23:44 PDT 2026
https://github.com/TIFitis created https://github.com/llvm/llvm-project/pull/185850
Further prevent corner cases of implicit declare mapper getting attached to data motion clauses like target enter/exit data.
>From 79b337b8a5139433a19e449eec4e64b6eff4fa41 Mon Sep 17 00:00:00 2001
From: Akash Banerjee <Akash.Banerjee at amd.com>
Date: Wed, 11 Mar 2026 09:41:29 +0000
Subject: [PATCH] [flang][OpenMP] Prevent attaching implicit mapper to data
motion clause
Further prevent corner cases of implicit declare mapper getting attached to data motion clauses like target enter/exit data.
---
flang/lib/Lower/OpenMP/ClauseProcessor.cpp | 13 ++++----
.../target-motion-skip-implicit-mapper.f90 | 30 +++++++++++++++++++
2 files changed, 37 insertions(+), 6 deletions(-)
create mode 100644 flang/test/Lower/OpenMP/target-motion-skip-implicit-mapper.f90
diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
index 4eed4231646ae..1f7c7a3b8296d 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
@@ -1770,10 +1770,11 @@ bool ClauseProcessor::processMap(
// For data-motion directives we avoid auto-attaching implicit default
// mappers. Deep recursive mapping there can conflict with explicit
// component enter/exit maps users commonly spell out.
- std::string mapperIdName = "__implicit_mapper";
- if (directive == llvm::omp::Directive::OMPD_target_enter_data ||
- directive == llvm::omp::Directive::OMPD_target_exit_data ||
- directive == llvm::omp::Directive::OMPD_target_update)
+ std::string mapperIdName = getMapperIdentifier(converter, mappers);
+ if ((directive == llvm::omp::Directive::OMPD_target_enter_data ||
+ directive == llvm::omp::Directive::OMPD_target_exit_data ||
+ directive == llvm::omp::Directive::OMPD_target_update) &&
+ mapperIdName == "__implicit_mapper")
mapperIdName.clear();
// If the map type is specified, then process it else set the appropriate
// default value
@@ -1821,8 +1822,6 @@ bool ClauseProcessor::processMap(
TODO(currentLocation,
"Support for iterator modifiers is not implemented yet");
}
- mapperIdName = getMapperIdentifier(converter, mappers);
-
processMapObjects(stmtCtx, clauseLocation,
std::get<omp::ObjectList>(clause.t), mapTypeBits,
parentMemberIndices, result.mapVars, *ptrMapSyms,
@@ -1854,6 +1853,8 @@ bool ClauseProcessor::processMotionClauses(lower::StatementContext &stmtCtx,
// Support motion modifiers: mapper, iterator.
std::string mapperIdName = getMapperIdentifier(converter, mapper);
+ if (mapperIdName == "__implicit_mapper")
+ mapperIdName.clear();
if (iterator) {
TODO(clauseLocation, "Iterator modifier is not supported yet");
}
diff --git a/flang/test/Lower/OpenMP/target-motion-skip-implicit-mapper.f90 b/flang/test/Lower/OpenMP/target-motion-skip-implicit-mapper.f90
new file mode 100644
index 0000000000000..067e7b06d2cf0
--- /dev/null
+++ b/flang/test/Lower/OpenMP/target-motion-skip-implicit-mapper.f90
@@ -0,0 +1,30 @@
+! RUN: bbc -emit-hlfir -fopenmp -fopenmp-version=52 %s -o - | FileCheck %s
+
+module m
+ type :: t
+ integer :: a
+ end type
+ !$omp declare mapper(t :: v) map(v%a)
+contains
+ subroutine test_motion(x)
+ type(t) :: x
+
+ !$omp target enter data map(to: x)
+ !$omp target update to(x)
+ !$omp target update from(x)
+ !$omp target update to(mapper(default): x)
+ !$omp target exit data map(from: x)
+ end subroutine test_motion
+end module m
+
+! CHECK-LABEL: func.func @_QMmPtest_motion(
+! CHECK: %[[ENTER:.*]] = omp.map.info {{.*}} map_clauses(to) capture(ByRef) -> {{.*}} {name = "x"}
+! CHECK: omp.target_enter_data map_entries(%[[ENTER]]
+! CHECK: %[[UPTO:.*]] = omp.map.info {{.*}} map_clauses(to) capture(ByRef) -> {{.*}} {name = "x"}
+! CHECK: omp.target_update map_entries(%[[UPTO]]
+! CHECK: %[[UPFROM:.*]] = omp.map.info {{.*}} map_clauses(from) capture(ByRef) -> {{.*}} {name = "x"}
+! CHECK: omp.target_update map_entries(%[[UPFROM]]
+! CHECK: %[[UPDEFAULT:.*]] = omp.map.info {{.*}} map_clauses(to) capture(ByRef) mapper(@{{.*}}t_omp_default_mapper) -> {{.*}} {name = "x"}
+! CHECK: omp.target_update map_entries(%[[UPDEFAULT]]
+! CHECK: %[[EXIT:.*]] = omp.map.info {{.*}} map_clauses(from) capture(ByRef) -> {{.*}} {name = "x"}
+! CHECK: omp.target_exit_data map_entries(%[[EXIT]]
More information about the flang-commits
mailing list