Skip to content

Commit 89b31c9

Browse files
[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.
1 parent a807bbe commit 89b31c9

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -487,13 +487,15 @@ static void getDeclareTargetInfo(
487487
} else if (const auto *clauseList{
488488
parser::Unwrap<parser::OmpClauseList>(spec.u)}) {
489489
List<Clause> clauses = makeClauses(*clauseList, semaCtx);
490-
if (clauses.empty() &&
491-
(!eval.getOwningProcedure()->isMainProgram() ||
492-
eval.getOwningProcedure()->getMainProgramSymbol())) {
493-
// Case: declare target, implicit capture of function
494-
symbolAndClause.emplace_back(
495-
mlir::omp::DeclareTargetCaptureClause::to,
496-
eval.getOwningProcedure()->getSubprogramSymbol());
490+
if (clauses.empty()) {
491+
Fortran::lower::pft::FunctionLikeUnit *owningProc =
492+
eval.getOwningProcedure();
493+
if (owningProc && (!owningProc->isMainProgram() ||
494+
owningProc->getMainProgramSymbol())) {
495+
// Case: declare target, implicit capture of function
496+
symbolAndClause.emplace_back(mlir::omp::DeclareTargetCaptureClause::to,
497+
owningProc->getSubprogramSymbol());
498+
}
497499
}
498500

499501
ClauseProcessor cp(converter, semaCtx, clauses);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
!RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s
2+
!RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-is-device %s -o - | FileCheck %s
3+
4+
!CHECK: module attributes
5+
module iface
6+
interface
7+
subroutine a()
8+
!$omp declare target
9+
end subroutine
10+
end interface
11+
end module

0 commit comments

Comments
 (0)