Skip to content

Commit 2a7328d

Browse files
[flang] Migrate away from ArrayRef(std::nullopt_t) (#149337)
ArrayRef(std::nullopt_t) has been deprecated. This patch replaces std::nullopt with {}. A subsequence patch will address those places where we need to replace std::nullopt with mlir::TypeRange{} or mlir::ValueRange{}.
1 parent fc37818 commit 2a7328d

19 files changed

+59
-70
lines changed

flang/lib/Lower/Bridge.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -810,11 +810,11 @@ class FirConverter : public Fortran::lower::AbstractConverter {
810810
fir::ExtendedValue read = fir::factory::genMutableBoxRead(
811811
*builder, loc, box, /*mayBePolymorphic=*/false);
812812
if (auto read_arr_box = read.getBoxOf<fir::ArrayBoxValue>()) {
813-
fir::factory::genInlinedAllocation(
814-
*builder, loc, *new_box, read_arr_box->getLBounds(),
815-
read_arr_box->getExtents(),
816-
/*lenParams=*/std::nullopt, name,
817-
/*mustBeHeap=*/true);
813+
fir::factory::genInlinedAllocation(*builder, loc, *new_box,
814+
read_arr_box->getLBounds(),
815+
read_arr_box->getExtents(),
816+
/*lenParams=*/{}, name,
817+
/*mustBeHeap=*/true);
818818
} else if (auto read_char_arr_box =
819819
read.getBoxOf<fir::CharArrayBoxValue>()) {
820820
fir::factory::genInlinedAllocation(
@@ -825,8 +825,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
825825
} else if (auto read_char_box =
826826
read.getBoxOf<fir::CharBoxValue>()) {
827827
fir::factory::genInlinedAllocation(*builder, loc, *new_box,
828-
/*lbounds=*/std::nullopt,
829-
/*extents=*/std::nullopt,
828+
/*lbounds=*/{},
829+
/*extents=*/{},
830830
read_char_box->getLen(), name,
831831
/*mustBeHeap=*/true);
832832
} else {
@@ -4590,8 +4590,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
45904590
// the static type of the LHS.
45914591
if (Fortran::evaluate::UnwrapExpr<Fortran::evaluate::NullPointer>(
45924592
assign.rhs))
4593-
return fir::factory::createUnallocatedBox(*builder, loc, lhsBoxType,
4594-
std::nullopt);
4593+
return fir::factory::createUnallocatedBox(*builder, loc, lhsBoxType, {});
45954594
hlfir::Entity rhs = Fortran::lower::convertExprToHLFIR(
45964595
loc, *this, assign.rhs, localSymbols, rhsContext);
45974596
// Create pointer descriptor value from the RHS.
@@ -5199,7 +5198,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
51995198
"LEN parameters");
52005199
lhsRealloc = fir::factory::genReallocIfNeeded(
52015200
*builder, loc, *lhsMutableBox,
5202-
/*shape=*/std::nullopt, lengthParams);
5201+
/*shape=*/{}, lengthParams);
52035202
return lhsRealloc->newValue;
52045203
}
52055204
return genExprAddr(assign.lhs, stmtCtx);
@@ -5271,7 +5270,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
52715270
if (lhsIsWholeAllocatable) {
52725271
assert(lhsRealloc.has_value());
52735272
fir::factory::finalizeRealloc(*builder, loc, *lhsMutableBox,
5274-
/*lbounds=*/std::nullopt,
5273+
/*lbounds=*/{},
52755274
/*takeLboundsIfRealloc=*/false,
52765275
*lhsRealloc);
52775276
}
@@ -6059,8 +6058,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
60596058
mlir::func::FuncOp func = fir::FirOpBuilder::createFunction(
60606059
mlir::UnknownLoc::get(context), getModuleOp(),
60616060
fir::NameUniquer::doGenerated("Sham"),
6062-
mlir::FunctionType::get(context, std::nullopt, std::nullopt),
6063-
symbolTable);
6061+
mlir::FunctionType::get(context, {}, {}), symbolTable);
60646062
func.addEntryBlock();
60656063
CHECK(!builder && "Expected builder to be uninitialized");
60666064
builder = new fir::FirOpBuilder(func, bridge.getKindMap(), symbolTable);

flang/lib/Lower/ConvertCall.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,7 @@ Fortran::lower::genCallOpAndResult(
496496
auto *context = builder.getContext();
497497
if (mlir::isa<fir::BoxProcType>(snd) &&
498498
mlir::isa<mlir::FunctionType>(fst.getType())) {
499-
auto funcTy =
500-
mlir::FunctionType::get(context, std::nullopt, std::nullopt);
499+
auto funcTy = mlir::FunctionType::get(context, {}, {});
501500
auto boxProcTy = builder.getBoxProcType(funcTy);
502501
if (mlir::Value host = argumentHostAssocs(converter, fst)) {
503502
cast = builder.create<fir::EmboxProcOp>(
@@ -1714,7 +1713,7 @@ void prepareUserCallArguments(
17141713
/*nonDeferredParams=*/mlir::ValueRange{},
17151714
/*mutableProperties=*/{});
17161715
fir::factory::associateMutableBox(builder, loc, ptrBox, actualExv,
1717-
/*lbounds=*/std::nullopt);
1716+
/*lbounds=*/{});
17181717
caller.placeInput(arg, irBox);
17191718
continue;
17201719
}

flang/lib/Lower/ConvertConstant.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ static mlir::Value genStructureComponentInit(
374374
"allocatable component value that is not NULL");
375375
} else {
376376
// Handle NULL() initialization
377-
mlir::Value componentValue{fir::factory::createUnallocatedBox(
378-
builder, loc, componentTy, std::nullopt)};
377+
mlir::Value componentValue{
378+
fir::factory::createUnallocatedBox(builder, loc, componentTy, {})};
379379
componentValue = builder.createConvert(loc, componentTy, componentValue);
380380

381381
return builder.create<fir::InsertValueOp>(

flang/lib/Lower/ConvertExpr.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ absentBoxToUnallocatedBox(fir::FirOpBuilder &builder, mlir::Location loc,
596596
mlir::Type boxType = box.getType();
597597
assert(mlir::isa<fir::BoxType>(boxType) && "argument must be a fir.box");
598598
mlir::Value emptyBox =
599-
fir::factory::createUnallocatedBox(builder, loc, boxType, std::nullopt);
599+
fir::factory::createUnallocatedBox(builder, loc, boxType, {});
600600
auto safeToReadBox =
601601
builder.create<mlir::arith::SelectOp>(loc, isPresent, box, emptyBox);
602602
return fir::substBase(exv, safeToReadBox);
@@ -2663,8 +2663,7 @@ class ScalarExprLowering {
26632663
/*nonDeferredParams=*/mlir::ValueRange{},
26642664
/*mutableProperties=*/{});
26652665
Fortran::lower::associateMutableBox(converter, loc, pointer, *expr,
2666-
/*lbounds=*/std::nullopt,
2667-
stmtCtx);
2666+
/*lbounds=*/{}, stmtCtx);
26682667
caller.placeInput(arg, irBox);
26692668
continue;
26702669
}
@@ -6186,7 +6185,7 @@ class ArrayExprLowering {
61866185
mlir::FunctionType memcpyType() {
61876186
auto ptrTy = mlir::LLVM::LLVMPointerType::get(builder.getContext());
61886187
llvm::SmallVector<mlir::Type> args = {ptrTy, ptrTy, builder.getI64Type()};
6189-
return mlir::FunctionType::get(builder.getContext(), args, std::nullopt);
6188+
return mlir::FunctionType::get(builder.getContext(), args, {});
61906189
}
61916190

61926191
/// Create a call to the LLVM memcpy intrinsic.

flang/lib/Lower/ConvertExprToHLFIR.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1945,7 +1945,7 @@ class HlfirBuilder {
19451945
fir::emitFatalError(loc, "pointer component designator could not be "
19461946
"lowered to mutable box");
19471947
Fortran::lower::associateMutableBox(converter, loc, *toBox, expr,
1948-
/*lbounds=*/std::nullopt, stmtCtx);
1948+
/*lbounds=*/{}, stmtCtx);
19491949
continue;
19501950
}
19511951

flang/lib/Lower/ConvertVariable.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,8 @@ mlir::Value Fortran::lower::genInitialDataTarget(
236236
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
237237
if (Fortran::evaluate::UnwrapExpr<Fortran::evaluate::NullPointer>(
238238
initialTarget))
239-
return fir::factory::createUnallocatedBox(
240-
builder, loc, boxType,
241-
/*nonDeferredParams=*/std::nullopt);
239+
return fir::factory::createUnallocatedBox(builder, loc, boxType,
240+
/*nonDeferredParams=*/{});
242241
// Pointer initial data target, and NULL(mold).
243242
for (const auto &sym : Fortran::evaluate::CollectSymbols(initialTarget)) {
244243
// Derived type component symbols should not be instantiated as objects
@@ -354,8 +353,8 @@ static mlir::Value genComponentDefaultInit(
354353
// From a standard point of view, pointer without initialization do not
355354
// need to be disassociated, but for sanity and simplicity, do it in
356355
// global constructor since this has no runtime cost.
357-
componentValue = fir::factory::createUnallocatedBox(
358-
builder, loc, componentTy, std::nullopt);
356+
componentValue =
357+
fir::factory::createUnallocatedBox(builder, loc, componentTy, {});
359358
} else if (Fortran::lower::hasDefaultInitialization(component)) {
360359
// Component type has default initialization.
361360
componentValue = genDefaultInitializerValue(converter, loc, component,
@@ -554,7 +553,7 @@ fir::GlobalOp Fortran::lower::defineGlobal(
554553
createGlobalInitialization(builder, global, [&](fir::FirOpBuilder &b) {
555554
mlir::Value box = fir::factory::createUnallocatedBox(
556555
b, loc, symTy,
557-
/*nonDeferredParams=*/std::nullopt,
556+
/*nonDeferredParams=*/{},
558557
/*typeSourceBox=*/{}, getAllocatorIdxFromDataAttr(dataAttr));
559558
b.create<fir::HasValueOp>(loc, box);
560559
});

flang/lib/Lower/HostAssociations.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,15 +410,15 @@ class CapturedArrays : public CapturedSymbols<CapturedArrays> {
410410
.genThen([&]() {
411411
fir::factory::associateMutableBox(builder, loc, boxInTuple,
412412
args.hostValue,
413-
/*lbounds=*/std::nullopt);
413+
/*lbounds=*/{});
414414
})
415415
.genElse([&]() {
416416
fir::factory::disassociateMutableBox(builder, loc, boxInTuple);
417417
})
418418
.end();
419419
} else {
420-
fir::factory::associateMutableBox(
421-
builder, loc, boxInTuple, args.hostValue, /*lbounds=*/std::nullopt);
420+
fir::factory::associateMutableBox(builder, loc, boxInTuple,
421+
args.hostValue, /*lbounds=*/{});
422422
}
423423
}
424424

flang/lib/Lower/IO.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ getNamelistGroup(Fortran::lower::AbstractConverter &converter,
528528
descAddr = builder.createTemporary(loc, boxType);
529529
fir::MutableBoxValue box = fir::MutableBoxValue(descAddr, {}, {});
530530
fir::factory::associateMutableBox(builder, loc, box, exv,
531-
/*lbounds=*/std::nullopt);
531+
/*lbounds=*/{});
532532
}
533533
descAddr = builder.createConvert(loc, descRefTy, descAddr);
534534
list = builder.create<fir::InsertValueOp>(loc, listTy, list, descAddr,

flang/lib/Optimizer/Builder/HLFIRTools.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ hlfir::Entity hlfir::createStackTempFromMold(mlir::Location loc,
14031403
builder.createTemporary(loc, sequenceType, tmpName, extents, lenParams);
14041404
} else {
14051405
alloc = builder.createTemporary(loc, mold.getFortranElementType(), tmpName,
1406-
/*shape=*/std::nullopt, lenParams);
1406+
/*shape=*/{}, lenParams);
14071407
}
14081408
auto declareOp =
14091409
builder.create<hlfir::DeclareOp>(loc, alloc, tmpName, shape, lenParams,

flang/lib/Optimizer/Builder/LowLevelIntrinsics.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,24 @@ mlir::func::FuncOp fir::factory::getRealloc(fir::FirOpBuilder &builder) {
3131
mlir::func::FuncOp
3232
fir::factory::getLlvmGetRounding(fir::FirOpBuilder &builder) {
3333
auto int32Ty = builder.getIntegerType(32);
34-
auto funcTy =
35-
mlir::FunctionType::get(builder.getContext(), std::nullopt, {int32Ty});
34+
auto funcTy = mlir::FunctionType::get(builder.getContext(), {}, {int32Ty});
3635
return builder.createFunction(builder.getUnknownLoc(), "llvm.get.rounding",
3736
funcTy);
3837
}
3938

4039
mlir::func::FuncOp
4140
fir::factory::getLlvmSetRounding(fir::FirOpBuilder &builder) {
4241
auto int32Ty = builder.getIntegerType(32);
43-
auto funcTy =
44-
mlir::FunctionType::get(builder.getContext(), {int32Ty}, std::nullopt);
42+
auto funcTy = mlir::FunctionType::get(builder.getContext(), {int32Ty}, {});
4543
return builder.createFunction(builder.getUnknownLoc(), "llvm.set.rounding",
4644
funcTy);
4745
}
4846

4947
mlir::func::FuncOp
5048
fir::factory::getLlvmInitTrampoline(fir::FirOpBuilder &builder) {
5149
auto ptrTy = builder.getRefType(builder.getIntegerType(8));
52-
auto funcTy = mlir::FunctionType::get(builder.getContext(),
53-
{ptrTy, ptrTy, ptrTy}, std::nullopt);
50+
auto funcTy =
51+
mlir::FunctionType::get(builder.getContext(), {ptrTy, ptrTy, ptrTy}, {});
5452
return builder.createFunction(builder.getUnknownLoc(), "llvm.init.trampoline",
5553
funcTy);
5654
}
@@ -90,8 +88,7 @@ mlir::func::FuncOp fir::factory::getFeenableexcept(fir::FirOpBuilder &builder) {
9088

9189
mlir::func::FuncOp fir::factory::getFegetexcept(fir::FirOpBuilder &builder) {
9290
auto int32Ty = builder.getIntegerType(32);
93-
auto funcTy =
94-
mlir::FunctionType::get(builder.getContext(), std::nullopt, {int32Ty});
91+
auto funcTy = mlir::FunctionType::get(builder.getContext(), {}, {int32Ty});
9592
return builder.createFunction(builder.getUnknownLoc(), "fegetexcept", funcTy);
9693
}
9794

0 commit comments

Comments
 (0)