[flang-commits] [flang] [OpenMP] Add PointerAssociateScalar to Cray Pointer used in the DSA (PR #133232)

Thirumalai Shaktivel via flang-commits flang-commits at lists.llvm.org
Thu Mar 27 03:52:12 PDT 2025


https://github.com/Thirumalai-Shaktivel created https://github.com/llvm/llvm-project/pull/133232

Issue: Cray Pointer is not associated to Cray Pointee, leading to Segmentation fault

Fix: GetUltimate, retrieves the base symbol in the current scope, which gets passed all the references and returns the original symbol

>From 2033cea526bbc2a0602b226a8996915b8ac4dfa3 Mon Sep 17 00:00:00 2001
From: Thirumalai-Shaktivel <thirumalaishaktivel at gmail.com>
Date: Thu, 27 Mar 2025 10:49:56 +0000
Subject: [PATCH] [OpenMP] Add PointerAssociateScalar to Cray Pointer used in
 the DSA

Issue: Cray Pointer is not associated to Cray Pointee,
leading to Segmentation fault

Fix: GetUltimate, retrieves the base symbol in the current scope,
which gets passed all the references and returns the original symbol
---
 flang/lib/Lower/ConvertExprToHLFIR.cpp    |  2 +-
 flang/test/Lower/OpenMP/cray-pointers.f90 | 33 +++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Lower/OpenMP/cray-pointers.f90

diff --git a/flang/lib/Lower/ConvertExprToHLFIR.cpp b/flang/lib/Lower/ConvertExprToHLFIR.cpp
index dc00e0b13f583..911bccdbfbe6f 100644
--- a/flang/lib/Lower/ConvertExprToHLFIR.cpp
+++ b/flang/lib/Lower/ConvertExprToHLFIR.cpp
@@ -279,7 +279,7 @@ class HlfirDesignatorBuilder {
   gen(const Fortran::evaluate::SymbolRef &symbolRef) {
     if (std::optional<fir::FortranVariableOpInterface> varDef =
             getSymMap().lookupVariableDefinition(symbolRef)) {
-      if (symbolRef->test(Fortran::semantics::Symbol::Flag::CrayPointee)) {
+      if (symbolRef.get().GetUltimate().test(Fortran::semantics::Symbol::Flag::CrayPointee)) {
         // The pointee is represented with a descriptor inheriting
         // the shape and type parameters of the pointee.
         // We have to update the base_addr to point to the current
diff --git a/flang/test/Lower/OpenMP/cray-pointers.f90 b/flang/test/Lower/OpenMP/cray-pointers.f90
new file mode 100644
index 0000000000000..1a0753244a461
--- /dev/null
+++ b/flang/test/Lower/OpenMP/cray-pointers.f90
@@ -0,0 +1,33 @@
+! Test lowering of Cray pointee references.
+! RUN: bbc -emit-hlfir -fopenmp %s -o - 2>&1 | FileCheck %s
+
+module test_host_assoc_cray_pointer
+  ! CHECK-LABEL: fir.global @_QMtest_host_assoc_cray_pointerEivar : i64
+  real*8 var(*)
+  ! CHECK-LABEL: fir.global  @_QMtest_host_assoc_cray_pointerEvar : !fir.array<?xf64>
+  pointer(ivar,var)
+
+contains
+
+  ! CHECK-LABEL: func.func @_QMtest_host_assoc_cray_pointerPset_cray_pointer()
+  subroutine set_cray_pointer
+    ! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?xf64>>>
+    ! CHECK: %[[IVAR_ADDR:.*]] = fir.address_of(@_QMtest_host_assoc_cray_pointerEivar) : !fir.ref<i64>
+    ! CHECK: %[[IVAR_DECL:.*]]:2 = hlfir.declare %[[IVAR_ADDR]] {uniq_name = "_QMtest_host_assoc_cray_pointerEivar"} : (!fir.ref<i64>) -> (!fir.ref<i64>, !fir.ref<i64>)
+    ! CHECK: %[[VAR_DECL:.*]]:2 = hlfir.declare %[[ALLOCA]] {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QMtest_host_assoc_cray_pointerEvar"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?xf64>>>>) -> (!fir.ref<!fir.box<!fir.ptr<!fir.array<?xf64>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf64>>>>)
+    real*8 pointee(2)
+    pointee(1) = 42.0
+
+    ivar = loc(pointee)
+
+    !$omp parallel default(none) shared(ivar)
+    ! CHECK: omp.parallel
+    ! CHECK: %[[I_01:.*]] = fir.convert %[[IVAR_DECL]]#0 : (!fir.ref<i64>) -> !fir.ref<!fir.ptr<i64>>
+    ! CHECK: %[[I_02:.*]] = fir.load %[[I_01]] : !fir.ref<!fir.ptr<i64>>
+    ! CHECK: %[[I_03:.*]] = fir.convert %[[VAR_DECL]]#0 : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?xf64>>>>) -> !fir.ref<!fir.box<none>>
+    ! CHECK: %[[I_04:.*]] = fir.convert %[[I_02]] : (!fir.ptr<i64>) -> !fir.llvm_ptr<i8>
+    ! CHECK: fir.call @_FortranAPointerAssociateScalar(%[[I_03]], %[[I_04]]) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
+    print *, var(1)
+    !$omp end parallel
+  end subroutine
+end module



More information about the flang-commits mailing list