[flang-commits] [flang] [flang] Migrate away from ArrayRef(std::nullopt_t) (PR #149337)
via flang-commits
flang-commits at lists.llvm.org
Thu Jul 17 08:41:46 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
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{}.
---
Patch is 25.62 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/149337.diff
19 Files Affected:
- (modified) flang/lib/Lower/Bridge.cpp (+11-13)
- (modified) flang/lib/Lower/ConvertCall.cpp (+2-3)
- (modified) flang/lib/Lower/ConvertConstant.cpp (+2-2)
- (modified) flang/lib/Lower/ConvertExpr.cpp (+3-4)
- (modified) flang/lib/Lower/ConvertExprToHLFIR.cpp (+1-1)
- (modified) flang/lib/Lower/ConvertVariable.cpp (+5-6)
- (modified) flang/lib/Lower/HostAssociations.cpp (+3-3)
- (modified) flang/lib/Lower/IO.cpp (+1-1)
- (modified) flang/lib/Optimizer/Builder/HLFIRTools.cpp (+1-1)
- (modified) flang/lib/Optimizer/Builder/LowLevelIntrinsics.cpp (+5-8)
- (modified) flang/lib/Optimizer/Builder/MutableBox.cpp (+14-14)
- (modified) flang/lib/Optimizer/Dialect/FIROps.cpp (+1-1)
- (modified) flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp (+1-1)
- (modified) flang/unittests/Optimizer/Builder/CharacterTest.cpp (+1-1)
- (modified) flang/unittests/Optimizer/Builder/ComplexTest.cpp (+1-1)
- (modified) flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp (+2-3)
- (modified) flang/unittests/Optimizer/Builder/HLFIRToolsTest.cpp (+1-1)
- (modified) flang/unittests/Optimizer/Builder/Runtime/RuntimeCallTestBase.h (+2-3)
- (modified) flang/unittests/Optimizer/FortranVariableTest.cpp (+2-3)
``````````diff
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index 33c1f1e7a3c3a..4241d12601242 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -810,11 +810,11 @@ class FirConverter : public Fortran::lower::AbstractConverter {
fir::ExtendedValue read = fir::factory::genMutableBoxRead(
*builder, loc, box, /*mayBePolymorphic=*/false);
if (auto read_arr_box = read.getBoxOf<fir::ArrayBoxValue>()) {
- fir::factory::genInlinedAllocation(
- *builder, loc, *new_box, read_arr_box->getLBounds(),
- read_arr_box->getExtents(),
- /*lenParams=*/std::nullopt, name,
- /*mustBeHeap=*/true);
+ fir::factory::genInlinedAllocation(*builder, loc, *new_box,
+ read_arr_box->getLBounds(),
+ read_arr_box->getExtents(),
+ /*lenParams=*/{}, name,
+ /*mustBeHeap=*/true);
} else if (auto read_char_arr_box =
read.getBoxOf<fir::CharArrayBoxValue>()) {
fir::factory::genInlinedAllocation(
@@ -825,8 +825,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
} else if (auto read_char_box =
read.getBoxOf<fir::CharBoxValue>()) {
fir::factory::genInlinedAllocation(*builder, loc, *new_box,
- /*lbounds=*/std::nullopt,
- /*extents=*/std::nullopt,
+ /*lbounds=*/{},
+ /*extents=*/{},
read_char_box->getLen(), name,
/*mustBeHeap=*/true);
} else {
@@ -4590,8 +4590,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
// the static type of the LHS.
if (Fortran::evaluate::UnwrapExpr<Fortran::evaluate::NullPointer>(
assign.rhs))
- return fir::factory::createUnallocatedBox(*builder, loc, lhsBoxType,
- std::nullopt);
+ return fir::factory::createUnallocatedBox(*builder, loc, lhsBoxType, {});
hlfir::Entity rhs = Fortran::lower::convertExprToHLFIR(
loc, *this, assign.rhs, localSymbols, rhsContext);
// Create pointer descriptor value from the RHS.
@@ -5199,7 +5198,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
"LEN parameters");
lhsRealloc = fir::factory::genReallocIfNeeded(
*builder, loc, *lhsMutableBox,
- /*shape=*/std::nullopt, lengthParams);
+ /*shape=*/{}, lengthParams);
return lhsRealloc->newValue;
}
return genExprAddr(assign.lhs, stmtCtx);
@@ -5271,7 +5270,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
if (lhsIsWholeAllocatable) {
assert(lhsRealloc.has_value());
fir::factory::finalizeRealloc(*builder, loc, *lhsMutableBox,
- /*lbounds=*/std::nullopt,
+ /*lbounds=*/{},
/*takeLboundsIfRealloc=*/false,
*lhsRealloc);
}
@@ -6059,8 +6058,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
mlir::func::FuncOp func = fir::FirOpBuilder::createFunction(
mlir::UnknownLoc::get(context), getModuleOp(),
fir::NameUniquer::doGenerated("Sham"),
- mlir::FunctionType::get(context, std::nullopt, std::nullopt),
- symbolTable);
+ mlir::FunctionType::get(context, {}, {}), symbolTable);
func.addEntryBlock();
CHECK(!builder && "Expected builder to be uninitialized");
builder = new fir::FirOpBuilder(func, bridge.getKindMap(), symbolTable);
diff --git a/flang/lib/Lower/ConvertCall.cpp b/flang/lib/Lower/ConvertCall.cpp
index 6ed15df0de754..071513303da25 100644
--- a/flang/lib/Lower/ConvertCall.cpp
+++ b/flang/lib/Lower/ConvertCall.cpp
@@ -496,8 +496,7 @@ Fortran::lower::genCallOpAndResult(
auto *context = builder.getContext();
if (mlir::isa<fir::BoxProcType>(snd) &&
mlir::isa<mlir::FunctionType>(fst.getType())) {
- auto funcTy =
- mlir::FunctionType::get(context, std::nullopt, std::nullopt);
+ auto funcTy = mlir::FunctionType::get(context, {}, {});
auto boxProcTy = builder.getBoxProcType(funcTy);
if (mlir::Value host = argumentHostAssocs(converter, fst)) {
cast = builder.create<fir::EmboxProcOp>(
@@ -1714,7 +1713,7 @@ void prepareUserCallArguments(
/*nonDeferredParams=*/mlir::ValueRange{},
/*mutableProperties=*/{});
fir::factory::associateMutableBox(builder, loc, ptrBox, actualExv,
- /*lbounds=*/std::nullopt);
+ /*lbounds=*/{});
caller.placeInput(arg, irBox);
continue;
}
diff --git a/flang/lib/Lower/ConvertConstant.cpp b/flang/lib/Lower/ConvertConstant.cpp
index 1051d50ce8a9a..1850b67898126 100644
--- a/flang/lib/Lower/ConvertConstant.cpp
+++ b/flang/lib/Lower/ConvertConstant.cpp
@@ -374,8 +374,8 @@ static mlir::Value genStructureComponentInit(
"allocatable component value that is not NULL");
} else {
// Handle NULL() initialization
- mlir::Value componentValue{fir::factory::createUnallocatedBox(
- builder, loc, componentTy, std::nullopt)};
+ mlir::Value componentValue{
+ fir::factory::createUnallocatedBox(builder, loc, componentTy, {})};
componentValue = builder.createConvert(loc, componentTy, componentValue);
return builder.create<fir::InsertValueOp>(
diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp
index f3430bfa3021e..0a1cd67789772 100644
--- a/flang/lib/Lower/ConvertExpr.cpp
+++ b/flang/lib/Lower/ConvertExpr.cpp
@@ -596,7 +596,7 @@ absentBoxToUnallocatedBox(fir::FirOpBuilder &builder, mlir::Location loc,
mlir::Type boxType = box.getType();
assert(mlir::isa<fir::BoxType>(boxType) && "argument must be a fir.box");
mlir::Value emptyBox =
- fir::factory::createUnallocatedBox(builder, loc, boxType, std::nullopt);
+ fir::factory::createUnallocatedBox(builder, loc, boxType, {});
auto safeToReadBox =
builder.create<mlir::arith::SelectOp>(loc, isPresent, box, emptyBox);
return fir::substBase(exv, safeToReadBox);
@@ -2663,8 +2663,7 @@ class ScalarExprLowering {
/*nonDeferredParams=*/mlir::ValueRange{},
/*mutableProperties=*/{});
Fortran::lower::associateMutableBox(converter, loc, pointer, *expr,
- /*lbounds=*/std::nullopt,
- stmtCtx);
+ /*lbounds=*/{}, stmtCtx);
caller.placeInput(arg, irBox);
continue;
}
@@ -6186,7 +6185,7 @@ class ArrayExprLowering {
mlir::FunctionType memcpyType() {
auto ptrTy = mlir::LLVM::LLVMPointerType::get(builder.getContext());
llvm::SmallVector<mlir::Type> args = {ptrTy, ptrTy, builder.getI64Type()};
- return mlir::FunctionType::get(builder.getContext(), args, std::nullopt);
+ return mlir::FunctionType::get(builder.getContext(), args, {});
}
/// Create a call to the LLVM memcpy intrinsic.
diff --git a/flang/lib/Lower/ConvertExprToHLFIR.cpp b/flang/lib/Lower/ConvertExprToHLFIR.cpp
index 9689f920840fb..7de433d6a201a 100644
--- a/flang/lib/Lower/ConvertExprToHLFIR.cpp
+++ b/flang/lib/Lower/ConvertExprToHLFIR.cpp
@@ -1945,7 +1945,7 @@ class HlfirBuilder {
fir::emitFatalError(loc, "pointer component designator could not be "
"lowered to mutable box");
Fortran::lower::associateMutableBox(converter, loc, *toBox, expr,
- /*lbounds=*/std::nullopt, stmtCtx);
+ /*lbounds=*/{}, stmtCtx);
continue;
}
diff --git a/flang/lib/Lower/ConvertVariable.cpp b/flang/lib/Lower/ConvertVariable.cpp
index 6c4516686f9d0..6cda742874ccf 100644
--- a/flang/lib/Lower/ConvertVariable.cpp
+++ b/flang/lib/Lower/ConvertVariable.cpp
@@ -236,9 +236,8 @@ mlir::Value Fortran::lower::genInitialDataTarget(
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
if (Fortran::evaluate::UnwrapExpr<Fortran::evaluate::NullPointer>(
initialTarget))
- return fir::factory::createUnallocatedBox(
- builder, loc, boxType,
- /*nonDeferredParams=*/std::nullopt);
+ return fir::factory::createUnallocatedBox(builder, loc, boxType,
+ /*nonDeferredParams=*/{});
// Pointer initial data target, and NULL(mold).
for (const auto &sym : Fortran::evaluate::CollectSymbols(initialTarget)) {
// Derived type component symbols should not be instantiated as objects
@@ -354,8 +353,8 @@ static mlir::Value genComponentDefaultInit(
// From a standard point of view, pointer without initialization do not
// need to be disassociated, but for sanity and simplicity, do it in
// global constructor since this has no runtime cost.
- componentValue = fir::factory::createUnallocatedBox(
- builder, loc, componentTy, std::nullopt);
+ componentValue =
+ fir::factory::createUnallocatedBox(builder, loc, componentTy, {});
} else if (Fortran::lower::hasDefaultInitialization(component)) {
// Component type has default initialization.
componentValue = genDefaultInitializerValue(converter, loc, component,
@@ -554,7 +553,7 @@ fir::GlobalOp Fortran::lower::defineGlobal(
createGlobalInitialization(builder, global, [&](fir::FirOpBuilder &b) {
mlir::Value box = fir::factory::createUnallocatedBox(
b, loc, symTy,
- /*nonDeferredParams=*/std::nullopt,
+ /*nonDeferredParams=*/{},
/*typeSourceBox=*/{}, getAllocatorIdxFromDataAttr(dataAttr));
b.create<fir::HasValueOp>(loc, box);
});
diff --git a/flang/lib/Lower/HostAssociations.cpp b/flang/lib/Lower/HostAssociations.cpp
index 6a44be65a6cde..95ea74b791b47 100644
--- a/flang/lib/Lower/HostAssociations.cpp
+++ b/flang/lib/Lower/HostAssociations.cpp
@@ -410,15 +410,15 @@ class CapturedArrays : public CapturedSymbols<CapturedArrays> {
.genThen([&]() {
fir::factory::associateMutableBox(builder, loc, boxInTuple,
args.hostValue,
- /*lbounds=*/std::nullopt);
+ /*lbounds=*/{});
})
.genElse([&]() {
fir::factory::disassociateMutableBox(builder, loc, boxInTuple);
})
.end();
} else {
- fir::factory::associateMutableBox(
- builder, loc, boxInTuple, args.hostValue, /*lbounds=*/std::nullopt);
+ fir::factory::associateMutableBox(builder, loc, boxInTuple,
+ args.hostValue, /*lbounds=*/{});
}
}
diff --git a/flang/lib/Lower/IO.cpp b/flang/lib/Lower/IO.cpp
index 69d72d9d63b68..53bf61922392d 100644
--- a/flang/lib/Lower/IO.cpp
+++ b/flang/lib/Lower/IO.cpp
@@ -528,7 +528,7 @@ getNamelistGroup(Fortran::lower::AbstractConverter &converter,
descAddr = builder.createTemporary(loc, boxType);
fir::MutableBoxValue box = fir::MutableBoxValue(descAddr, {}, {});
fir::factory::associateMutableBox(builder, loc, box, exv,
- /*lbounds=*/std::nullopt);
+ /*lbounds=*/{});
}
descAddr = builder.createConvert(loc, descRefTy, descAddr);
list = builder.create<fir::InsertValueOp>(loc, listTy, list, descAddr,
diff --git a/flang/lib/Optimizer/Builder/HLFIRTools.cpp b/flang/lib/Optimizer/Builder/HLFIRTools.cpp
index e59a6bf2bf224..fb6f0dbf719fb 100644
--- a/flang/lib/Optimizer/Builder/HLFIRTools.cpp
+++ b/flang/lib/Optimizer/Builder/HLFIRTools.cpp
@@ -1403,7 +1403,7 @@ hlfir::Entity hlfir::createStackTempFromMold(mlir::Location loc,
builder.createTemporary(loc, sequenceType, tmpName, extents, lenParams);
} else {
alloc = builder.createTemporary(loc, mold.getFortranElementType(), tmpName,
- /*shape=*/std::nullopt, lenParams);
+ /*shape=*/{}, lenParams);
}
auto declareOp =
builder.create<hlfir::DeclareOp>(loc, alloc, tmpName, shape, lenParams,
diff --git a/flang/lib/Optimizer/Builder/LowLevelIntrinsics.cpp b/flang/lib/Optimizer/Builder/LowLevelIntrinsics.cpp
index 64d70d70829fb..3fb7fab099965 100644
--- a/flang/lib/Optimizer/Builder/LowLevelIntrinsics.cpp
+++ b/flang/lib/Optimizer/Builder/LowLevelIntrinsics.cpp
@@ -31,8 +31,7 @@ mlir::func::FuncOp fir::factory::getRealloc(fir::FirOpBuilder &builder) {
mlir::func::FuncOp
fir::factory::getLlvmGetRounding(fir::FirOpBuilder &builder) {
auto int32Ty = builder.getIntegerType(32);
- auto funcTy =
- mlir::FunctionType::get(builder.getContext(), std::nullopt, {int32Ty});
+ auto funcTy = mlir::FunctionType::get(builder.getContext(), {}, {int32Ty});
return builder.createFunction(builder.getUnknownLoc(), "llvm.get.rounding",
funcTy);
}
@@ -40,8 +39,7 @@ fir::factory::getLlvmGetRounding(fir::FirOpBuilder &builder) {
mlir::func::FuncOp
fir::factory::getLlvmSetRounding(fir::FirOpBuilder &builder) {
auto int32Ty = builder.getIntegerType(32);
- auto funcTy =
- mlir::FunctionType::get(builder.getContext(), {int32Ty}, std::nullopt);
+ auto funcTy = mlir::FunctionType::get(builder.getContext(), {int32Ty}, {});
return builder.createFunction(builder.getUnknownLoc(), "llvm.set.rounding",
funcTy);
}
@@ -49,8 +47,8 @@ fir::factory::getLlvmSetRounding(fir::FirOpBuilder &builder) {
mlir::func::FuncOp
fir::factory::getLlvmInitTrampoline(fir::FirOpBuilder &builder) {
auto ptrTy = builder.getRefType(builder.getIntegerType(8));
- auto funcTy = mlir::FunctionType::get(builder.getContext(),
- {ptrTy, ptrTy, ptrTy}, std::nullopt);
+ auto funcTy =
+ mlir::FunctionType::get(builder.getContext(), {ptrTy, ptrTy, ptrTy}, {});
return builder.createFunction(builder.getUnknownLoc(), "llvm.init.trampoline",
funcTy);
}
@@ -90,8 +88,7 @@ mlir::func::FuncOp fir::factory::getFeenableexcept(fir::FirOpBuilder &builder) {
mlir::func::FuncOp fir::factory::getFegetexcept(fir::FirOpBuilder &builder) {
auto int32Ty = builder.getIntegerType(32);
- auto funcTy =
- mlir::FunctionType::get(builder.getContext(), std::nullopt, {int32Ty});
+ auto funcTy = mlir::FunctionType::get(builder.getContext(), {}, {int32Ty});
return builder.createFunction(builder.getUnknownLoc(), "fegetexcept", funcTy);
}
diff --git a/flang/lib/Optimizer/Builder/MutableBox.cpp b/flang/lib/Optimizer/Builder/MutableBox.cpp
index d944a4c98473e..93abedc43936d 100644
--- a/flang/lib/Optimizer/Builder/MutableBox.cpp
+++ b/flang/lib/Optimizer/Builder/MutableBox.cpp
@@ -521,23 +521,23 @@ void fir::factory::associateMutableBox(fir::FirOpBuilder &builder,
mlir::Value sourceBox;
if (auto *polyBox = source.getBoxOf<fir::PolymorphicValue>())
sourceBox = polyBox->getSourceBox();
- writer.updateMutableBox(p.getAddr(), /*lbounds=*/std::nullopt,
- /*extents=*/std::nullopt,
- /*lengths=*/std::nullopt, sourceBox);
+ writer.updateMutableBox(p.getAddr(), /*lbounds=*/{},
+ /*extents=*/{},
+ /*lengths=*/{}, sourceBox);
},
[&](const fir::UnboxedValue &addr) {
- writer.updateMutableBox(addr, /*lbounds=*/std::nullopt,
- /*extents=*/std::nullopt,
- /*lengths=*/std::nullopt);
+ writer.updateMutableBox(addr, /*lbounds=*/{},
+ /*extents=*/{},
+ /*lengths=*/{});
},
[&](const fir::CharBoxValue &ch) {
- writer.updateMutableBox(ch.getAddr(), /*lbounds=*/std::nullopt,
- /*extents=*/std::nullopt, {ch.getLen()});
+ writer.updateMutableBox(ch.getAddr(), /*lbounds=*/{},
+ /*extents=*/{}, {ch.getLen()});
},
[&](const fir::ArrayBoxValue &arr) {
writer.updateMutableBox(arr.getAddr(),
lbounds.empty() ? arr.getLBounds() : lbounds,
- arr.getExtents(), /*lengths=*/std::nullopt);
+ arr.getExtents(), /*lengths=*/{});
},
[&](const fir::CharArrayBoxValue &arr) {
writer.updateMutableBox(arr.getAddr(),
@@ -634,11 +634,11 @@ void fir::factory::associateMutableBoxWithRemap(
source.match(
[&](const fir::PolymorphicValue &p) {
writer.updateMutableBox(cast(p.getAddr()), lbounds, extents,
- /*lengths=*/std::nullopt);
+ /*lengths=*/{});
},
[&](const fir::UnboxedValue &addr) {
writer.updateMutableBox(cast(addr), lbounds, extents,
- /*lengths=*/std::nullopt);
+ /*lengths=*/{});
},
[&](const fir::CharBoxValue &ch) {
writer.updateMutableBox(cast(ch.getAddr()), lbounds, extents,
@@ -646,7 +646,7 @@ void fir::factory::associateMutableBoxWithRemap(
},
[&](const fir::ArrayBoxValue &arr) {
writer.updateMutableBox(cast(arr.getAddr()), lbounds, extents,
- /*lengths=*/std::nullopt);
+ /*lengths=*/{});
},
[&](const fir::CharArrayBoxValue &arr) {
writer.updateMutableBox(cast(arr.getAddr()), lbounds, extents,
@@ -755,8 +755,8 @@ static mlir::Value allocateAndInitNewStorage(fir::FirOpBuilder &builder,
// there is no way to know here if a derived type needs it or not. But the
// information is available at compile time and could be reflected here
// somehow.
- mlir::Value irBox = createNewFirBox(builder, loc, box, newStorage,
- std::nullopt, extents, lengths);
+ mlir::Value irBox =
+ createNewFirBox(builder, loc, box, newStorage, {}, extents, lengths);
fir::runtime::genDerivedTypeInitialize(builder, loc, irBox);
}
return newStorage;
diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp
index b6bf2753b80ce..cf20d84cbbcdb 100644
--- a/flang/lib/Optimizer/Dialect/FIROps.cpp
+++ b/flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -4448,7 +4448,7 @@ llvm::LogicalResult fir::UnboxProcOp::verify() {
void fir::IfOp::build(mlir::OpBuilder &builder, mlir::OperationState &result,
mlir::Value cond, bool withElseRegion) {
- build(builder, result, std::nullopt, cond, withElseRegion);
+ build(builder, result, {}, cond, withElseRegion);
}
void fir::IfOp::build(mlir::OpBuilder &builder, mlir::OperationState &result,
diff --git a/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp b/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp
index 58f2b57712974..00ca6731c035b 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp
+++ b/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp
@@ -296,7 +296,7 @@ struct SetLengthOpConversion
llvm::StringRef tmpName{".tmp"};
llvm::SmallVector<mlir::Value, 1> lenParams{adaptor.getLength()};
auto alloca = builder.createTemporary(loc, c...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/149337
More information about the flang-commits
mailing list