Skip to content

Commit 8c52568

Browse files
committed
Remove Windows special case
It turns out SIG_DFL and SIG_IGN are part of the C89 standard so I presume they are supported on Windows.
1 parent d3e5b56 commit 8c52568

File tree

1 file changed

+16
-35
lines changed

1 file changed

+16
-35
lines changed

flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -245,45 +245,12 @@ void fir::runtime::genSignal(fir::FirOpBuilder &builder, mlir::Location loc,
245245
mlir::Value number, mlir::Value handler,
246246
mlir::Value status) {
247247
assert(mlir::isa<mlir::IntegerType>(number.getType()));
248-
if (status)
249-
assert(mlir::isa<mlir::IntegerType>(fir::unwrapRefType(status.getType())));
250248
mlir::Type int64 = builder.getIntegerType(64);
251249
number = builder.create<fir::ConvertOp>(loc, int64, number);
252250

253-
// we can return like a function or via the status argument
254-
auto returnStatus = [&](mlir::Value stat) -> mlir::Value {
255-
if (status) {
256-
// status might be dynamically optional, so test if it is present
257-
mlir::Value isPresent =
258-
builder.create<IsPresentOp>(loc, builder.getI1Type(), status);
259-
builder.genIfOp(loc, /*results=*/{}, isPresent, /*withElseRegion=*/false)
260-
.genThen([&]() {
261-
stat = builder.create<fir::ConvertOp>(
262-
loc, fir::unwrapRefType(status.getType()), stat);
263-
builder.create<fir::StoreOp>(loc, stat, status);
264-
})
265-
.end();
266-
}
267-
return {};
268-
};
269-
270251
mlir::Type handlerUnwrappedTy = fir::unwrapRefType(handler.getType());
271252
if (mlir::isa_and_nonnull<mlir::IntegerType>(handlerUnwrappedTy)) {
272-
#if _WIN32
273-
// The windows documentation doesn't mention any support for passing
274-
// SIG_DFL or SIG_IGN as integer arguments, so just return an error.
275-
276-
// reinterpret cast: the GNU extension is defined with STATUS as an integer
277-
// but on Windows SIG_ERR is a void *
278-
const std::int64_t sigErrVal =
279-
static_cast<std::int64_t>(reinterpret_cast<std::uintptr_t>(SIG_ERR));
280-
mlir::Value sigErr = builder.createIntegerConstant(loc, int64, sigErrVal);
281-
returnStatus(sigErr);
282-
errno = EINVAL;
283-
return;
284-
#endif // _WIN32
285-
// else just pass the integer as a function pointer like one would to
286-
// signal(2)
253+
// pass the integer as a function pointer like one would to signal(2)
287254
handler = builder.create<fir::LoadOp>(loc, handler);
288255
mlir::Type fnPtrTy = fir::LLVMPointerType::get(
289256
mlir::FunctionType::get(handler.getContext(), {}, {}));
@@ -298,7 +265,21 @@ void fir::runtime::genSignal(fir::FirOpBuilder &builder, mlir::Location loc,
298265
mlir::Value stat =
299266
builder.create<fir::CallOp>(loc, func, mlir::ValueRange{number, handler})
300267
->getResult(0);
301-
returnStatus(stat);
268+
269+
// return status code via status argument (if present)
270+
if (status) {
271+
assert(mlir::isa<mlir::IntegerType>(fir::unwrapRefType(status.getType())));
272+
// status might be dynamically optional, so test if it is present
273+
mlir::Value isPresent =
274+
builder.create<IsPresentOp>(loc, builder.getI1Type(), status);
275+
builder.genIfOp(loc, /*results=*/{}, isPresent, /*withElseRegion=*/false)
276+
.genThen([&]() {
277+
stat = builder.create<fir::ConvertOp>(
278+
loc, fir::unwrapRefType(status.getType()), stat);
279+
builder.create<fir::StoreOp>(loc, stat, status);
280+
})
281+
.end();
282+
}
302283
}
303284

304285
void fir::runtime::genSleep(fir::FirOpBuilder &builder, mlir::Location loc,

0 commit comments

Comments
 (0)