Skip to content

Commit 18b7e8f

Browse files
[flang] Add missing argument to pause_code test and clean up PAUSE lowering
1 parent 0e8d546 commit 18b7e8f

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

flang/lib/Lower/Runtime.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ void Fortran::lower::genSyncTeamStatement(
264264
void Fortran::lower::genPauseStatement(
265265
Fortran::lower::AbstractConverter &converter,
266266
const Fortran::parser::PauseStmt &stmt) {
267-
267+
268268
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
269269
mlir::Location loc = converter.getCurrentLocation();
270270
Fortran::lower::StatementContext stmtCtx;
@@ -275,38 +275,39 @@ void Fortran::lower::genPauseStatement(
275275

276276
if (stmt.v.has_value()) {
277277
const auto &code = stmt.v.value();
278-
auto expr = converter.genExprValue(*Fortran::semantics::GetExpr(code), stmtCtx);
278+
auto expr =
279+
converter.genExprValue(*Fortran::semantics::GetExpr(code), stmtCtx);
279280
expr.match(
280281
// Character-valued expression -> call PauseStatementText (CHAR, LEN)
281282
[&](const fir::CharBoxValue &x) {
282-
callee = fir::runtime::getRuntimeFunc<mkRTKey(PauseStatementText)>(loc, builder);
283+
callee = fir::runtime::getRuntimeFunc<mkRTKey(PauseStatementText)>(
284+
loc, builder);
283285
calleeType = callee.getFunctionType();
284286

285287
operands.push_back(
286288
builder.createConvert(loc, calleeType.getInput(0), x.getAddr()));
287289
operands.push_back(
288290
builder.createConvert(loc, calleeType.getInput(1), x.getLen()));
289291
},
290-
// Numeric/unboxed value -> call PauseStatement which accepts an integer code.
292+
// Unboxed value -> call PauseStatementInt which accepts an integer.
291293
[&](fir::UnboxedValue x) {
292-
callee = fir::runtime::getRuntimeFunc<mkRTKey(PauseStatementInt)>(loc, builder);
293-
calleeType = callee.getFunctionType();
294-
if (calleeType.getNumInputs() >= 1) {
295-
mlir::Value cast =
296-
builder.createConvert(loc, calleeType.getInput(0), x);
297-
operands.push_back(cast);
298-
}
294+
callee = fir::runtime::getRuntimeFunc<mkRTKey(PauseStatementInt)>(
295+
loc, builder);
296+
calleeType = callee.getFunctionType();
297+
assert(calleeType.getNumInputs() >= 1);
298+
mlir::Value cast =
299+
builder.createConvert(loc, calleeType.getInput(0), x);
300+
operands.push_back(cast);
299301
},
300302
[&](auto) {
301303
fir::emitFatalError(loc, "unhandled expression in PAUSE");
302-
// mlir::emitError(loc, "unhandled expression in PAUSE");
303-
std::exit(1);
304304
});
305305
} else {
306-
callee = fir::runtime::getRuntimeFunc<mkRTKey(PauseStatement)>(loc, builder);
306+
callee =
307+
fir::runtime::getRuntimeFunc<mkRTKey(PauseStatement)>(loc, builder);
307308
calleeType = callee.getFunctionType();
308309
}
309-
310+
310311
fir::CallOp::create(builder, loc, callee, operands);
311312

312313
// NOTE: PAUSE does not terminate the current block. The program may resume
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
! RUN: bbc %s -emit-fir --canonicalize -o - | FileCheck %s
1+
! RUN: bbc %s -emit-fir -hlfir=false --canonicalize -o - | FileCheck %s
22

33
! CHECK-LABEL: pause_test
44
subroutine pause_test()
5+
pause
56
! CHECK: fir.call @_Fortran{{.*}}PauseStatement()
67
! CHECK-NEXT: return
7-
pause
88
end subroutine
99

1010
! CHECK-LABEL: pause_code
1111
subroutine pause_code()
1212
pause 42
13-
! CHECK: fir.call @_Fortran{{.*}}PauseStatementInt
14-
! CHECK-NEXT: return
13+
! CHECK: %[[c42:.*]] = arith.constant 42 : i32
14+
! CHECK: fir.call @_Fortran{{.*}}PauseStatementInt(%[[c42]])
15+
! CHECK-NEXT: return
1516
end subroutine
1617

1718
! CHECK-LABEL: pause_msg
1819
subroutine pause_msg()
19-
pause "hello"
20+
pause 'hello'
2021
! CHECK-DAG: %[[five:.*]] = arith.constant 5 : index
2122
! CHECK-DAG: %[[lit:.*]] = fir.address_of(@_QQ{{.*}}) : !fir.ref<!fir.char<1,5>>
2223
! CHECK-DAG: %[[buff:.*]] = fir.convert %[[lit]] : (!fir.ref<!fir.char<1,5>>) -> !fir.ref<i8>
@@ -26,4 +27,5 @@ subroutine pause_msg()
2627
end subroutine
2728

2829
! CHECK-DAG: func private @_Fortran{{.*}}PauseStatement
30+
! CHECK-DAG: func private @_Fortran{{.*}}PauseStatementInt
2931
! CHECK-DAG: func private @_Fortran{{.*}}PauseStatementText

0 commit comments

Comments
 (0)