[flang-commits] [flang] Skip POINTER components in implicit mapper generation (PR #177848)

Deval Gupta via flang-commits flang-commits at lists.llvm.org
Sun Jan 25 02:31:55 PST 2026


https://github.com/devalgupta404 created https://github.com/llvm/llvm-project/pull/177848

closes #176956 
This PR skips POINTER components when checking if a derived type requires an implicit mapper to prevent incorrect deep copy behavior

>From 4ee49e98e2ca5a71b968e1a9c0cf40f34c576788 Mon Sep 17 00:00:00 2001
From: devalgupta404 <devalgupta4 at gmail.com>
Date: Sun, 25 Jan 2026 15:16:00 +0530
Subject: [PATCH] Skip POINTER components in implicit mapper generation

Signed-off-by: devalgupta404 <devalgupta4 at gmail.com>
---
 flang/lib/Lower/OpenMP/Utils.cpp              |  3 ++
 .../test/Lower/OpenMP/pointer-components.f90  | 46 +++++++++++++++++++
 2 files changed, 49 insertions(+)
 create mode 100644 flang/test/Lower/OpenMP/pointer-components.f90

diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp
index dce8580856664..93b90c1a5694a 100644
--- a/flang/lib/Lower/OpenMP/Utils.cpp
+++ b/flang/lib/Lower/OpenMP/Utils.cpp
@@ -193,6 +193,9 @@ bool requiresImplicitDefaultDeclareMapper(
       if (component.attrs().test(semantics::Attr::ALLOCATABLE))
         return true;
 
+      if (component.attrs().test(semantics::Attr::POINTER))
+        continue;
+
       if (const semantics::DeclTypeSpec *declType = component.GetType())
         if (const auto *nested = declType->AsDerived())
           if (requiresMapper(*nested))
diff --git a/flang/test/Lower/OpenMP/pointer-components.f90 b/flang/test/Lower/OpenMP/pointer-components.f90
new file mode 100644
index 0000000000000..59898dc53d5bf
--- /dev/null
+++ b/flang/test/Lower/OpenMP/pointer-components.f90
@@ -0,0 +1,46 @@
+! RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=52 %s -o - | FileCheck %s
+
+! Test 1: POINTER-only derieved type should not trigger implicit mapper 
+subroutine test_pointer_only
+  type :: dt_pointer
+    real, pointer :: p(:)
+  end type
+
+  type(dt_pointer) :: obj
+
+  ! CHECK-NOT: omp.declare_mapper @{{.*}}dt_pointer
+  !$omp target map(tofrom: obj)
+  !$omp end target
+end subroutine test_pointer_only
+
+! Test 2: POINTER to derieved type with ALLOCATABLE must not trigger mapper 
+subroutine test_pointer_to_allocatable_dt
+  type :: inner_dt
+    real, allocatable :: data(:)
+  end type
+
+  type :: outer_dt
+    type(inner_dt), pointer :: nested_ptr
+  end type
+
+  type(outer_dt) :: obj
+
+  ! CHECK-NOT: omp.declare_mapper @{{.*}}outer_dt
+  !$omp target map(tofrom: obj)
+  !$omp end target
+end subroutine test_pointer_to_allocatable_dt
+
+! Test 3: ALLOCATABLE member must still trigger mapper
+subroutine test_allocatable_still_triggers_mapper
+  type :: alloc_dt
+    real, allocatable :: a(:)
+  end type
+
+  type(alloc_dt) :: obj
+  allocate(obj%a(4))
+
+  ! CHECK: omp.declare_mapper @{{.*}}alloc_dt
+  !$omp target map(tofrom: obj)
+    obj%a(1) = 1.0
+  !$omp end target
+end subroutine test_allocatable_still_triggers_mapper
\ No newline at end of file



More information about the flang-commits mailing list