Skip to content

[flang][Lower] Treat directives with nested evaluations as constructs #91614

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

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions flang/lib/Lower/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4548,9 +4548,13 @@ class FirConverter : public Fortran::lower::AbstractConverter {
// constructs, this can be done for either the end construct statement,
// or for the construct itself, which will skip this code if the
// end statement was visited first and generated a branch.
Fortran::lower::pft::Evaluation *successor =
eval.isConstruct() ? eval.getLastNestedEvaluation().lexicalSuccessor
: eval.lexicalSuccessor;
Fortran::lower::pft::Evaluation *successor = [&]() {
if (eval.isConstruct() ||
(eval.isDirective() && eval.hasNestedEvaluations()))
return eval.getLastNestedEvaluation().lexicalSuccessor;
return eval.lexicalSuccessor;
}();

if (successor && blockIsUnterminated()) {
if (successor->isIntermediateConstructStmt() &&
successor->parentConstruct->lowerAsUnstructured())
Expand Down
25 changes: 25 additions & 0 deletions flang/test/Lower/branching-directive.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
!RUN: flang-new -fc1 -emit-hlfir -fopenmp -o - %s | FileCheck %s

!https://github.com/llvm/llvm-project/issues/91526

!CHECK: cf.cond_br %{{[0-9]+}}, ^bb[[THEN:[0-9]+]], ^bb[[ELSE:[0-9]+]]
!CHECK: ^bb[[THEN]]:
!CHECK: cf.br ^bb[[EXIT:[0-9]+]]
!CHECK: ^bb[[ELSE]]:
!CHECK: fir.call @_FortranAStopStatement
!CHECK: fir.unreachable
!CHECK: ^bb[[EXIT]]:

subroutine simple(y)
implicit none
logical, intent(in) :: y
integer :: i
if (y) then
!$omp parallel
i = 1
!$omp end parallel
else
stop 1
end if
end subroutine simple