Skip to content

Commit

Permalink
[flang] Handle character constant for error code in STOP stmt
Browse files Browse the repository at this point in the history
Handle character constant ofr error code in the STOP statement.

Depends on D118992

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: kiranchandramohan, schweitz

Differential Revision: https://reviews.llvm.org/D118993
  • Loading branch information
clementval committed Feb 7, 2022
1 parent 74751f4 commit a8d48fe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 8 additions & 1 deletion flang/lib/Lower/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ void Fortran::lower::genStopStatement(
llvm::dbgs() << '\n');
expr.match(
[&](const fir::CharBoxValue &x) {
TODO(loc, "STOP CharBoxValue first operand not lowered yet");
callee = fir::runtime::getRuntimeFunc<mkRTKey(StopStatementText)>(
loc, builder);
calleeType = callee.getType();
// Creates a pair of operands for the CHARACTER and its LEN.
operands.push_back(
builder.createConvert(loc, calleeType.getInput(0), x.getAddr()));
operands.push_back(
builder.createConvert(loc, calleeType.getInput(1), x.getLen()));
},
[&](fir::UnboxedValue x) {
callee = fir::runtime::getRuntimeFunc<mkRTKey(StopStatement)>(
Expand Down
12 changes: 12 additions & 0 deletions flang/test/Lower/stop-statement.f90
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,15 @@ subroutine stop_quiet()
! CHECK: fir.call @_Fortran{{.*}}StopStatement(%[[c0]], %[[false]], %[[bi1]])
! CHECK-NEXT: fir.unreachable
end subroutine

! CHECK-LABEL stop_char_lit
subroutine stop_char_lit
! CHECK-DAG: %[[false:.*]] = arith.constant false
! CHECK-DAG: %[[five:.*]] = arith.constant 5 : index
! CHECK-DAG: %[[lit:.*]] = fir.address_of(@_QQ{{.*}}) : !fir.ref<!fir.char<1,5>>
! CHECK-DAG: %[[buff:.*]] = fir.convert %[[lit]] : (!fir.ref<!fir.char<1,5>>) -> !fir.ref<i8>
! CHECK-DAG: %[[len:.*]] = fir.convert %[[five]] : (index) -> i64
! CHECK: fir.call @{{.*}}StopStatementText(%[[buff]], %[[len]], %[[false]], %[[false]]) :
! CHECK-NEXT: fir.unreachable
stop 'crash'
end subroutine stop_char_lit

0 comments on commit a8d48fe

Please sign in to comment.