From 15a9a72ee68166c0cff3f036cacd3c82be66c729 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 17 Dec 2022 22:22:47 +0000 Subject: [PATCH] [flang] llvm::Optional::value() => => operator*/operator-> std::optional::value() has undesired exception checking semantics and is unavailable in older Xcode (see _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS). The call sites block std::optional migration. --- flang/include/flang/Lower/IterationSpace.h | 2 +- flang/lib/Lower/Bridge.cpp | 8 ++++---- flang/lib/Lower/ConvertCall.cpp | 2 +- flang/lib/Lower/ConvertExpr.cpp | 19 +++++++++---------- flang/lib/Lower/ConvertExprToHLFIR.cpp | 10 ++++------ flang/lib/Lower/CustomIntrinsicCall.cpp | 4 ++-- flang/lib/Optimizer/Builder/FIRBuilder.cpp | 5 ++--- flang/lib/Optimizer/Transforms/AffinePromotion.cpp | 2 +- 8 files changed, 24 insertions(+), 28 deletions(-) diff --git a/flang/include/flang/Lower/IterationSpace.h b/flang/include/flang/Lower/IterationSpace.h index ce134f1..218e9e1 100644 --- a/flang/include/flang/Lower/IterationSpace.h +++ b/flang/include/flang/Lower/IterationSpace.h @@ -475,7 +475,7 @@ public: /// Return the outermost loop in this FORALL nest. fir::DoLoopOp getOuterLoop() { assert(outerLoop.has_value()); - return outerLoop.value(); + return *outerLoop; } /// Return the statement context for the entire, outermost FORALL construct. diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp index c58acf8..f29f785 100644 --- a/flang/lib/Lower/Bridge.cpp +++ b/flang/lib/Lower/Bridge.cpp @@ -2764,10 +2764,10 @@ private: llvm_unreachable("unknown category"); } if (lhsIsWholeAllocatable) - fir::factory::finalizeRealloc( - *builder, loc, lhsMutableBox.value(), - /*lbounds=*/std::nullopt, /*takeLboundsIfRealloc=*/false, - lhsRealloc.value()); + fir::factory::finalizeRealloc(*builder, loc, *lhsMutableBox, + /*lbounds=*/std::nullopt, + /*takeLboundsIfRealloc=*/false, + *lhsRealloc); }, // [2] User defined assignment. If the context is a scalar diff --git a/flang/lib/Lower/ConvertCall.cpp b/flang/lib/Lower/ConvertCall.cpp index a2852b3..ef7fdf2 100644 --- a/flang/lib/Lower/ConvertCall.cpp +++ b/flang/lib/Lower/ConvertCall.cpp @@ -368,7 +368,7 @@ fir::ExtendedValue Fortran::lower::genCallOpAndResult( if (caller.mustSaveResult()) builder.create(loc, callResult, - fir::getBase(allocatedResult.value()), + fir::getBase(*allocatedResult), arrayResultShape, resultLengths); if (allocatedResult) { diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp index e0dc827..6194304 100644 --- a/flang/lib/Lower/ConvertExpr.cpp +++ b/flang/lib/Lower/ConvertExpr.cpp @@ -1473,7 +1473,7 @@ public: if (con.Rank() > 0) return genArrayLit(con); if (auto ctor = con.GetScalarValue()) - return genval(ctor.value()); + return genval(*ctor); fir::emitFatalError(getLoc(), "constant of derived type has no constructor"); } @@ -3669,9 +3669,8 @@ public: mlir::Value oldInnerArg = modifyOp.getSequence(); std::size_t offset = explicitSpace->argPosition(oldInnerArg); explicitSpace->setInnerArg(offset, fir::getBase(lexv)); - fir::ExtendedValue exv = - arrayModifyToExv(builder, loc, explicitSpace->getLhsLoad(0).value(), - modifyOp.getResult(0)); + fir::ExtendedValue exv = arrayModifyToExv( + builder, loc, *explicitSpace->getLhsLoad(0), modifyOp.getResult(0)); genScalarUserDefinedAssignmentCall(builder, loc, userAssignment, exv, elementalExv); } else { @@ -3846,7 +3845,7 @@ private: } mlir::Value val = builder.createConvert(loc, eleTy, origVal); if (isBoundsSpec()) { - auto lbs = lbounds.value(); + auto lbs = *lbounds; if (lbs.size() > 0) { // Rebox the value with user-specified shift. auto shiftTy = fir::ShiftType::get(eleTy.getContext(), lbs.size()); @@ -3855,10 +3854,10 @@ private: mlir::Value{}); } } else if (isBoundsRemap()) { - auto lbs = lbounds.value(); + auto lbs = *lbounds; if (lbs.size() > 0) { // Rebox the value with user-specified shift and shape. - auto shapeShiftArgs = flatZip(lbs, ubounds.value()); + auto shapeShiftArgs = flatZip(lbs, *ubounds); auto shapeTy = fir::ShapeShiftType::get(eleTy.getContext(), lbs.size()); mlir::Value shapeShift = builder.create(loc, shapeTy, shapeShiftArgs); @@ -6245,7 +6244,7 @@ private: charLen = builder.createTemporary(loc, builder.getI64Type()); mlir::Value castLen = builder.createConvert(loc, builder.getI64Type(), fir::getLen(exv)); - builder.create(loc, castLen, charLen.value()); + builder.create(loc, castLen, *charLen); } } stmtCtx.finalizeAndPop(); @@ -6259,7 +6258,7 @@ private: // Convert to extended value. if (fir::isa_char(seqTy.getEleTy())) { - auto len = builder.create(loc, charLen.value()); + auto len = builder.create(loc, *charLen); return {fir::CharArrayBoxValue{mem, len, extents}, /*needCopy=*/false}; } return {fir::ArrayBoxValue{mem, extents}, /*needCopy=*/false}; @@ -6327,7 +6326,7 @@ private: charLen = builder.createTemporary(loc, builder.getI64Type()); mlir::Value castLen = builder.createConvert(loc, builder.getI64Type(), fir::getLen(exv)); - builder.create(loc, castLen, charLen.value()); + builder.create(loc, castLen, *charLen); } } mem = builder.createConvert(loc, fir::HeapType::get(resTy), mem); diff --git a/flang/lib/Lower/ConvertExprToHLFIR.cpp b/flang/lib/Lower/ConvertExprToHLFIR.cpp index fcad425..06bee48 100644 --- a/flang/lib/Lower/ConvertExprToHLFIR.cpp +++ b/flang/lib/Lower/ConvertExprToHLFIR.cpp @@ -457,9 +457,9 @@ struct BinaryOp &expr) { mlir::Type resType = Fortran::lower::TypeBuilder::genType(getConverter(), expr); - return Fortran::lower::convertCallToHLFIR(getLoc(), getConverter(), expr, - resType, getSymMap(), - getStmtCtx()) - .value(); + return *Fortran::lower::convertCallToHLFIR( + getLoc(), getConverter(), expr, resType, getSymMap(), getStmtCtx()); } template diff --git a/flang/lib/Lower/CustomIntrinsicCall.cpp b/flang/lib/Lower/CustomIntrinsicCall.cpp index 2ceab2a..51dcbde 100644 --- a/flang/lib/Lower/CustomIntrinsicCall.cpp +++ b/flang/lib/Lower/CustomIntrinsicCall.cpp @@ -175,12 +175,12 @@ lowerIshftc(fir::FirOpBuilder &builder, mlir::Location loc, isPresentCheck(2) && "only ISHFTC SIZE arg is expected to be dynamically optional here"); assert(retTy && "ISFHTC must have a return type"); - mlir::Type resultType = retTy.value(); + mlir::Type resultType = *retTy; llvm::SmallVector args; args.push_back(getOperand(0)); args.push_back(getOperand(1)); args.push_back(builder - .genIfOp(loc, {resultType}, isPresentCheck(2).value(), + .genIfOp(loc, {resultType}, *isPresentCheck(2), /*withElseRegion=*/true) .genThen([&]() { fir::ExtendedValue sizeExv = getOperand(2); diff --git a/flang/lib/Optimizer/Builder/FIRBuilder.cpp b/flang/lib/Optimizer/Builder/FIRBuilder.cpp index e7b8762..946f93b 100644 --- a/flang/lib/Optimizer/Builder/FIRBuilder.cpp +++ b/flang/lib/Optimizer/Builder/FIRBuilder.cpp @@ -1355,9 +1355,8 @@ fir::factory::getExtentFromTriplet(mlir::Value lb, mlir::Value ub, if (auto lbInt = getConstantValue(lb)) { if (auto ubInt = getConstantValue(ub)) { if (auto strideInt = getConstantValue(stride)) { - if (strideInt.value() != 0) { - std::int64_t extent = - 1 + (ubInt.value() - lbInt.value()) / strideInt.value(); + if (*strideInt != 0) { + std::int64_t extent = 1 + (*ubInt - *lbInt) / *strideInt; if (extent > 0) return extent; } diff --git a/flang/lib/Optimizer/Transforms/AffinePromotion.cpp b/flang/lib/Optimizer/Transforms/AffinePromotion.cpp index 558ba86..0762b6f 100644 --- a/flang/lib/Optimizer/Transforms/AffinePromotion.cpp +++ b/flang/lib/Optimizer/Transforms/AffinePromotion.cpp @@ -179,7 +179,7 @@ struct AffineIfCondition { mlir::IntegerSet getIntegerSet() const { assert(hasIntegerSet() && "integer set is missing"); - return integerSet.value(); + return *integerSet; } mlir::ValueRange getAffineArgs() const { return affineArgs; } -- 2.7.4