[flang-commits] [flang] 89b31c9 - [Flang][OpenMP] Fix a crash for declare target in an interface (#117709)
via flang-commits
flang-commits at lists.llvm.org
Wed Nov 27 06:20:38 PST 2024
Author: Kiran Chandramohan
Date: 2024-11-27T14:20:34Z
New Revision: 89b31c9c32f2cd2c038fe2b12d9c66a53c779fc1
URL: https://github.com/llvm/llvm-project/commit/89b31c9c32f2cd2c038fe2b12d9c66a53c779fc1
DIFF: https://github.com/llvm/llvm-project/commit/89b31c9c32f2cd2c038fe2b12d9c66a53c779fc1.diff
LOG: [Flang][OpenMP] Fix a crash for declare target in an interface (#117709)
This is a point fix for the crash in #116426. Leaving the bug open to
further explore declare target issues for interfaces.
Added:
flang/test/Lower/OpenMP/declare-target-interface.f90
Modified:
flang/lib/Lower/OpenMP/OpenMP.cpp
Removed:
################################################################################
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index ea2d1eb66bfea5..747e90b212a350 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