diff options
author | jeanPerier <jperier@nvidia.com> | 2024-04-04 15:31:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-04 15:31:54 +0200 |
commit | ea88bb16485a34db58333637d8558ff57e6a1329 (patch) | |
tree | 14e8fa19916cbb140a40d67335959d2cd7c37541 | |
parent | a1f4ac7704255627ac33ad67a22be5ac030f6179 (diff) | |
download | llvm-ea88bb16485a34db58333637d8558ff57e6a1329.zip llvm-ea88bb16485a34db58333637d8558ff57e6a1329.tar.gz llvm-ea88bb16485a34db58333637d8558ff57e6a1329.tar.bz2 |
[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 https://github.com/llvm/llvm-project/issues/66581.
-rw-r--r-- | flang/lib/Lower/Runtime.cpp | 9 | ||||
-rw-r--r-- | flang/test/Lower/stop-statement.f90 | 4 |
2 files changed, 7 insertions, 6 deletions
diff --git a/flang/lib/Lower/Runtime.cpp b/flang/lib/Lower/Runtime.cpp index e769592..3474832 100644 --- a/flang/lib/Lower/Runtime.cpp +++ b/flang/lib/Lower/Runtime.cpp @@ -55,6 +55,8 @@ static void genUnreachable(fir::FirOpBuilder &builder, mlir::Location loc) { void Fortran::lower::genStopStatement( Fortran::lower::AbstractConverter &converter, const Fortran::parser::StopStmt &stmt) { + const bool isError = std::get<Fortran::parser::StopStmt::Kind>(stmt.t) == + Fortran::parser::StopStmt::Kind::ErrorStop; fir::FirOpBuilder &builder = converter.getFirOpBuilder(); mlir::Location loc = converter.getCurrentLocation(); Fortran::lower::StatementContext stmtCtx; @@ -94,13 +96,12 @@ void Fortran::lower::genStopStatement( } else { callee = fir::runtime::getRuntimeFunc<mkRTKey(StopStatement)>(loc, builder); calleeType = callee.getFunctionType(); - operands.push_back( - builder.createIntegerConstant(loc, calleeType.getInput(0), 0)); + // Default to values are advised in F'2023 11.4 p2. + operands.push_back(builder.createIntegerConstant( + loc, calleeType.getInput(0), isError ? 1 : 0)); } // Second operand indicates ERROR STOP - bool isError = std::get<Fortran::parser::StopStmt::Kind>(stmt.t) == - Fortran::parser::StopStmt::Kind::ErrorStop; operands.push_back(builder.createIntegerConstant( loc, calleeType.getInput(operands.size()), isError)); diff --git a/flang/test/Lower/stop-statement.f90 b/flang/test/Lower/stop-statement.f90 index bc94a7e..cf0665c 100644 --- a/flang/test/Lower/stop-statement.f90 +++ b/flang/test/Lower/stop-statement.f90 @@ -21,10 +21,10 @@ end subroutine ! CHECK-LABEL: stop_error subroutine stop_error() error stop - ! CHECK-DAG: %[[c0:.*]] = arith.constant 0 : i32 + ! CHECK-DAG: %[[c_1:.*]] = arith.constant 1 : i32 ! CHECK-DAG: %[[true:.*]] = arith.constant true ! CHECK-DAG: %[[false:.*]] = arith.constant false - ! CHECK: fir.call @_Fortran{{.*}}StopStatement(%[[c0]], %[[true]], %[[false]]) + ! CHECK: fir.call @_Fortran{{.*}}StopStatement(%[[c_1]], %[[true]], %[[false]]) ! CHECK-NEXT: fir.unreachable end subroutine |