Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OpenMP] Add PointerAssociateScalar to Cray Pointer used in the DSA #133232

Merged
merged 6 commits into from
Mar 29, 2025

Conversation

Thirumalai-Shaktivel
Copy link
Member

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

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
@llvmbot
Copy link
Member

llvmbot commented Mar 27, 2025

@llvm/pr-subscribers-flang-semantics
@llvm/pr-subscribers-flang-openmp

@llvm/pr-subscribers-flang-fir-hlfir

Author: Thirumalai Shaktivel (Thirumalai-Shaktivel)

Changes

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


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

2 Files Affected:

  • (modified) flang/lib/Lower/ConvertExprToHLFIR.cpp (+1-1)
  • (added) flang/test/Lower/OpenMP/cray-pointers.f90 (+33)
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

Copy link

github-actions bot commented Mar 27, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@ronlieb ronlieb requested review from ronlieb and dpalermo March 27, 2025 11:03
Copy link
Contributor

@dpalermo dpalermo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified this works for me. The lit tests also capture the failing case I know of. Thanks!

Copy link
Contributor

@mjklemm mjklemm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mjklemm mjklemm merged commit 374a5be into llvm:main Mar 29, 2025
11 checks passed
@Thirumalai-Shaktivel Thirumalai-Shaktivel deleted the llvm/cray_ptr_03 branch April 1, 2025 05:42
@Thirumalai-Shaktivel
Copy link
Member Author

Thirumalai-Shaktivel commented Apr 1, 2025

Thanks for the reviews!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang:openmp flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants