Skip to content

Commit a427aa9

Browse files
authored
[flang][Lower] Treat directives with nested evaluations as constructs (#91614)
When generating block terminators in `genFIR(Evaluation)`, treat `Directives` with nested evaluations the same way as `Constructs` to determine the successor block. This fixes #91526
1 parent e3ca558 commit a427aa9

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

flang/lib/Lower/Bridge.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4548,9 +4548,13 @@ class FirConverter : public Fortran::lower::AbstractConverter {
45484548
// constructs, this can be done for either the end construct statement,
45494549
// or for the construct itself, which will skip this code if the
45504550
// end statement was visited first and generated a branch.
4551-
Fortran::lower::pft::Evaluation *successor =
4552-
eval.isConstruct() ? eval.getLastNestedEvaluation().lexicalSuccessor
4553-
: eval.lexicalSuccessor;
4551+
Fortran::lower::pft::Evaluation *successor = [&]() {
4552+
if (eval.isConstruct() ||
4553+
(eval.isDirective() && eval.hasNestedEvaluations()))
4554+
return eval.getLastNestedEvaluation().lexicalSuccessor;
4555+
return eval.lexicalSuccessor;
4556+
}();
4557+
45544558
if (successor && blockIsUnterminated()) {
45554559
if (successor->isIntermediateConstructStmt() &&
45564560
successor->parentConstruct->lowerAsUnstructured())
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
!RUN: flang-new -fc1 -emit-hlfir -fopenmp -o - %s | FileCheck %s
2+
3+
!https://github.com/llvm/llvm-project/issues/91526
4+
5+
!CHECK: cf.cond_br %{{[0-9]+}}, ^bb[[THEN:[0-9]+]], ^bb[[ELSE:[0-9]+]]
6+
!CHECK: ^bb[[THEN]]:
7+
!CHECK: cf.br ^bb[[EXIT:[0-9]+]]
8+
!CHECK: ^bb[[ELSE]]:
9+
!CHECK: fir.call @_FortranAStopStatement
10+
!CHECK: fir.unreachable
11+
!CHECK: ^bb[[EXIT]]:
12+
13+
subroutine simple(y)
14+
implicit none
15+
logical, intent(in) :: y
16+
integer :: i
17+
if (y) then
18+
!$omp parallel
19+
i = 1
20+
!$omp end parallel
21+
else
22+
stop 1
23+
end if
24+
end subroutine simple
25+

0 commit comments

Comments
 (0)