[flang-commits] [flang] [Flang][OpenMP] Fix a crash for declare target in an interface (PR #117709)

Kiran Chandramohan via flang-commits flang-commits at lists.llvm.org
Tue Nov 26 04:33:41 PST 2024


https://github.com/kiranchandramohan created https://github.com/llvm/llvm-project/pull/117709

This is a point fix for the crash in #116426. Leaving the bug open to further explore declare target issues for interfaces.

>From a72e670bd177c7f84cabd3d7b07d50cdce2842c7 Mon Sep 17 00:00:00 2001
From: Kiran Chandramohan <kiran.chandramohan at arm.com>
Date: Tue, 26 Nov 2024 12:27:52 +0000
Subject: [PATCH] [Flang][OpenMP] Fix a crash for declare target in an
 interface

This is a point fix for the crash in #116426.
---
 flang/lib/Lower/OpenMP/OpenMP.cpp                | 16 +++++++++-------
 .../Lower/OpenMP/declare-target-interface.f90    | 11 +++++++++++
 2 files changed, 20 insertions(+), 7 deletions(-)
 create mode 100644 flang/test/Lower/OpenMP/declare-target-interface.f90

diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index a2779213a1a15a..7afb7edc822101 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -487,13 +487,15 @@ static void getDeclareTargetInfo(
   } else if (const auto *clauseList{
                  parser::Unwrap<parser::OmpClauseList>(spec.u)}) {
     List<Clause> clauses = makeClauses(*clauseList, semaCtx);
-    if (clauses.empty() &&
-        (!eval.getOwningProcedure()->isMainProgram() ||
-         eval.getOwningProcedure()->getMainProgramSymbol())) {
-      // Case: declare target, implicit capture of function
-      symbolAndClause.emplace_back(
-          mlir::omp::DeclareTargetCaptureClause::to,
-          eval.getOwningProcedure()->getSubprogramSymbol());
+    if (clauses.empty()) {
+      Fortran::lower::pft::FunctionLikeUnit *owningProc =
+          eval.getOwningProcedure();
+      if (owningProc && (!owningProc->isMainProgram() ||
+                         owningProc->getMainProgramSymbol())) {
+        // Case: declare target, implicit capture of function
+        symbolAndClause.emplace_back(mlir::omp::DeclareTargetCaptureClause::to,
+                                     owningProc->getSubprogramSymbol());
+      }
     }
 
     ClauseProcessor cp(converter, semaCtx, clauses);
diff --git a/flang/test/Lower/OpenMP/declare-target-interface.f90 b/flang/test/Lower/OpenMP/declare-target-interface.f90
new file mode 100644
index 00000000000000..e92d1905c7ad05
--- /dev/null
+++ b/flang/test/Lower/OpenMP/declare-target-interface.f90
@@ -0,0 +1,11 @@
+!RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s
+!RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-is-device %s -o - | FileCheck %s
+
+!CHECK: module attributes
+module iface
+interface
+  subroutine a()
+  !$omp declare target
+  end subroutine
+end interface
+end module



More information about the flang-commits mailing list