Skip to content

Commit ea88bb1

Browse files
authored
[flang] Return 1 in ERROR STOP without user provided stop-code (#87501)
See F'2023 section 11.4: "If the stop-code in an ERROR STOP statement is of type character or does not appear, it is recommended that a processor-dependent nonzero value be supplied as the process exit status" Fixes #66581.
1 parent a1f4ac7 commit ea88bb1

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

flang/lib/Lower/Runtime.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ static void genUnreachable(fir::FirOpBuilder &builder, mlir::Location loc) {
5555
void Fortran::lower::genStopStatement(
5656
Fortran::lower::AbstractConverter &converter,
5757
const Fortran::parser::StopStmt &stmt) {
58+
const bool isError = std::get<Fortran::parser::StopStmt::Kind>(stmt.t) ==
59+
Fortran::parser::StopStmt::Kind::ErrorStop;
5860
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
5961
mlir::Location loc = converter.getCurrentLocation();
6062
Fortran::lower::StatementContext stmtCtx;
@@ -94,13 +96,12 @@ void Fortran::lower::genStopStatement(
9496
} else {
9597
callee = fir::runtime::getRuntimeFunc<mkRTKey(StopStatement)>(loc, builder);
9698
calleeType = callee.getFunctionType();
97-
operands.push_back(
98-
builder.createIntegerConstant(loc, calleeType.getInput(0), 0));
99+
// Default to values are advised in F'2023 11.4 p2.
100+
operands.push_back(builder.createIntegerConstant(
101+
loc, calleeType.getInput(0), isError ? 1 : 0));
99102
}
100103

101104
// Second operand indicates ERROR STOP
102-
bool isError = std::get<Fortran::parser::StopStmt::Kind>(stmt.t) ==
103-
Fortran::parser::StopStmt::Kind::ErrorStop;
104105
operands.push_back(builder.createIntegerConstant(
105106
loc, calleeType.getInput(operands.size()), isError));
106107

flang/test/Lower/stop-statement.f90

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ subroutine stop_code()
2121
! CHECK-LABEL: stop_error
2222
subroutine stop_error()
2323
error stop
24-
! CHECK-DAG: %[[c0:.*]] = arith.constant 0 : i32
24+
! CHECK-DAG: %[[c_1:.*]] = arith.constant 1 : i32
2525
! CHECK-DAG: %[[true:.*]] = arith.constant true
2626
! CHECK-DAG: %[[false:.*]] = arith.constant false
27-
! CHECK: fir.call @_Fortran{{.*}}StopStatement(%[[c0]], %[[true]], %[[false]])
27+
! CHECK: fir.call @_Fortran{{.*}}StopStatement(%[[c_1]], %[[true]], %[[false]])
2828
! CHECK-NEXT: fir.unreachable
2929
end subroutine
3030

0 commit comments

Comments
 (0)