Skip to content

Commit acd7544

Browse files
[Flang] Lower the FailImage Statement
Lowering of FailImage statement generates a runtime call and the unreachable operation. The unreachable operation cannot terminate a structured operation like the IF operation, hence mark as unstructured. Note: This patch is part of upstreaming code from the fir-dev branch of https://github.com/flang-compiler/f18-llvm-project. Reviewed By: clementval Differential Revision: https://reviews.llvm.org/D124520 Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
1 parent 8052f4d commit acd7544

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

flang/lib/Lower/Bridge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2013,7 +2013,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
20132013

20142014
// call FAIL IMAGE in runtime
20152015
void genFIR(const Fortran::parser::FailImageStmt &stmt) {
2016-
TODO(toLocation(), "FailImageStmt lowering");
2016+
genFailImageStatement(*this);
20172017
}
20182018

20192019
// call STOP, ERROR STOP in runtime

flang/lib/Lower/PFTBuilder.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,11 @@ class PFTBuilder {
744744
assert(construct && "missing EXIT construct");
745745
markBranchTarget(eval, *construct->constructExit);
746746
},
747+
[&](const parser::FailImageStmt &) {
748+
eval.isUnstructured = true;
749+
if (eval.lexicalSuccessor->lexicalSuccessor)
750+
markSuccessorAsNewBlock(eval);
751+
},
747752
[&](const parser::GotoStmt &s) { markBranchTarget(eval, s.v); },
748753
[&](const parser::IfStmt &) {
749754
eval.lexicalSuccessor->isNewBlock = true;

flang/test/Lower/fail_image.f90

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
! RUN: bbc -emit-fir -o - %s | FileCheck %s
2+
! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s
3+
4+
! CHECK-LABEL: func @_QPfail_image_test
5+
subroutine fail_image_test(fail)
6+
logical :: fail
7+
! CHECK: cond_br {{.*}}, ^[[BB1:.*]], ^[[BB2:.*]]
8+
! CHECK: ^[[BB1]]:
9+
if (fail) then
10+
! CHECK: {{.*}} = fir.call @_FortranAFailImageStatement() : () -> none
11+
! CHECK-NEXT: fir.unreachable
12+
FAIL IMAGE
13+
end if
14+
! CHECK: ^[[BB2]]:
15+
! CHECK-NEXT: br ^[[BB3:.*]]
16+
! CHECK-NEXT: ^[[BB3]]
17+
! CEHCK-NEXT: return
18+
return
19+
end subroutine
20+
! CHECK-LABEL: func private @_FortranAFailImageStatement() -> none attributes {fir.runtime}

flang/test/Lower/pre-fir-tree04.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ Subroutine test_coarray
6161
end if
6262
! CHECK: <<End IfConstruct>>
6363

64-
! CHECK: <<IfConstruct>>
64+
! CHECK: <<IfConstruct!>>
6565
if (y<0.) then
6666
! CHECK: FailImageStmt
6767
fail image
6868
end if
69-
! CHECK: <<End IfConstruct>>
69+
! CHECK: <<End IfConstruct!>>
7070
end

0 commit comments

Comments
 (0)