[flang] Handle character constant for error code in STOP stmt

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
This commit is contained in:
Valentin Clement 2022-02-07 12:18:24 +01:00
parent 74751f4b0c
commit a8d48fe0fe
No known key found for this signature in database
GPG Key ID: 086D54783C928776
2 changed files with 20 additions and 1 deletions

View File

@ -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)>(

View File

@ -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