[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>
This commit is contained in:
Kiran Chandramohan 2022-04-27 12:19:54 +00:00
parent 8052f4d22a
commit acd75440c6
4 changed files with 28 additions and 3 deletions

View File

@ -2013,7 +2013,7 @@ private:
// call FAIL IMAGE in runtime
void genFIR(const Fortran::parser::FailImageStmt &stmt) {
TODO(toLocation(), "FailImageStmt lowering");
genFailImageStatement(*this);
}
// call STOP, ERROR STOP in runtime

View File

@ -744,6 +744,11 @@ private:
assert(construct && "missing EXIT construct");
markBranchTarget(eval, *construct->constructExit);
},
[&](const parser::FailImageStmt &) {
eval.isUnstructured = true;
if (eval.lexicalSuccessor->lexicalSuccessor)
markSuccessorAsNewBlock(eval);
},
[&](const parser::GotoStmt &s) { markBranchTarget(eval, s.v); },
[&](const parser::IfStmt &) {
eval.lexicalSuccessor->isNewBlock = true;

View File

@ -0,0 +1,20 @@
! RUN: bbc -emit-fir -o - %s | FileCheck %s
! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s
! CHECK-LABEL: func @_QPfail_image_test
subroutine fail_image_test(fail)
logical :: fail
! CHECK: cond_br {{.*}}, ^[[BB1:.*]], ^[[BB2:.*]]
! CHECK: ^[[BB1]]:
if (fail) then
! CHECK: {{.*}} = fir.call @_FortranAFailImageStatement() : () -> none
! CHECK-NEXT: fir.unreachable
FAIL IMAGE
end if
! CHECK: ^[[BB2]]:
! CHECK-NEXT: br ^[[BB3:.*]]
! CHECK-NEXT: ^[[BB3]]
! CEHCK-NEXT: return
return
end subroutine
! CHECK-LABEL: func private @_FortranAFailImageStatement() -> none attributes {fir.runtime}

View File

@ -61,10 +61,10 @@ Subroutine test_coarray
end if
! CHECK: <<End IfConstruct>>
! CHECK: <<IfConstruct>>
! CHECK: <<IfConstruct!>>
if (y<0.) then
! CHECK: FailImageStmt
fail image
end if
! CHECK: <<End IfConstruct>>
! CHECK: <<End IfConstruct!>>
end