From 7430894a6573665c18b97599db76a331fa0b25eb Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 29 Jul 2022 10:57:25 -0700 Subject: [PATCH] Replace Optional::hasValue with has_value or operator bool. NFC --- bolt/include/bolt/Core/BinaryFunction.h | 2 +- bolt/lib/Rewrite/DWARFRewriter.cpp | 2 +- bolt/lib/Rewrite/RewriteInstance.cpp | 2 +- bolt/unittests/Core/BinaryContext.cpp | 4 ++-- bolt/unittests/Core/MCPlusBuilder.cpp | 2 +- clang/lib/Driver/OffloadBundler.cpp | 2 +- mlir/examples/toy/Ch1/include/toy/AST.h | 2 +- mlir/examples/toy/Ch1/parser/AST.cpp | 2 +- mlir/examples/toy/Ch2/include/toy/AST.h | 2 +- mlir/examples/toy/Ch2/mlir/MLIRGen.cpp | 2 +- mlir/examples/toy/Ch2/parser/AST.cpp | 2 +- mlir/examples/toy/Ch3/include/toy/AST.h | 2 +- mlir/examples/toy/Ch3/mlir/MLIRGen.cpp | 2 +- mlir/examples/toy/Ch3/parser/AST.cpp | 2 +- mlir/examples/toy/Ch4/include/toy/AST.h | 2 +- mlir/examples/toy/Ch4/mlir/MLIRGen.cpp | 2 +- mlir/examples/toy/Ch4/parser/AST.cpp | 2 +- mlir/examples/toy/Ch5/include/toy/AST.h | 2 +- mlir/examples/toy/Ch5/mlir/MLIRGen.cpp | 2 +- mlir/examples/toy/Ch5/parser/AST.cpp | 2 +- mlir/examples/toy/Ch6/include/toy/AST.h | 2 +- mlir/examples/toy/Ch6/mlir/MLIRGen.cpp | 2 +- mlir/examples/toy/Ch6/parser/AST.cpp | 2 +- mlir/examples/toy/Ch7/include/toy/AST.h | 2 +- mlir/examples/toy/Ch7/mlir/MLIRGen.cpp | 2 +- mlir/examples/toy/Ch7/parser/AST.cpp | 2 +- 26 files changed, 27 insertions(+), 27 deletions(-) diff --git a/bolt/include/bolt/Core/BinaryFunction.h b/bolt/include/bolt/Core/BinaryFunction.h index 02d00e3..16c0ea3 100644 --- a/bolt/include/bolt/Core/BinaryFunction.h +++ b/bolt/include/bolt/Core/BinaryFunction.h @@ -994,7 +994,7 @@ public: bool hasName(const std::string &FunctionName) const { auto Res = forEachName([&](StringRef Name) { return Name == FunctionName; }); - return Res.hasValue(); + return Res.has_value(); } /// Check if any of function names matches the given regex. diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp index 3466f5c..810ca36 100644 --- a/bolt/lib/Rewrite/DWARFRewriter.cpp +++ b/bolt/lib/Rewrite/DWARFRewriter.cpp @@ -673,7 +673,7 @@ void DWARFRewriter::updateUnitDebugInfo( AttrOffset = AttrVal->Offset; Value = AttrVal->V; const Optional Result = Value.getAsAddress(); - if (Result.hasValue()) { + if (Result) { const uint64_t Address = *Result; uint64_t NewAddress = 0; if (const BinaryFunction *Function = diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp index e2957ef..5bc6374 100644 --- a/bolt/lib/Rewrite/RewriteInstance.cpp +++ b/bolt/lib/Rewrite/RewriteInstance.cpp @@ -2739,7 +2739,7 @@ void RewriteInstance::selectFunctionsToProcess() { Function.forEachName([&ForceFunctionsNR](StringRef Name) { return ForceFunctionsNR.count(Name.str()); }); - return Match.hasValue(); + return Match.has_value(); } for (std::string &Name : opts::SkipFunctionNames) diff --git a/bolt/unittests/Core/BinaryContext.cpp b/bolt/unittests/Core/BinaryContext.cpp index 6e5c6c4..3620163 100644 --- a/bolt/unittests/Core/BinaryContext.cpp +++ b/bolt/unittests/Core/BinaryContext.cpp @@ -77,9 +77,9 @@ TEST_P(BinaryContextTester, BaseAddress) { Optional BaseAddress = BC->getBaseAddressForMapping(0x7f13f5556000, 0x10e8c000); - ASSERT_TRUE(BaseAddress.hasValue()); + ASSERT_TRUE(BaseAddress.has_value()); ASSERT_EQ(*BaseAddress, 0x7f13e46c9000ULL); BaseAddress = BC->getBaseAddressForMapping(0x7f13f5556000, 0x137a000); - ASSERT_FALSE(BaseAddress.hasValue()); + ASSERT_FALSE(BaseAddress.has_value()); } diff --git a/bolt/unittests/Core/MCPlusBuilder.cpp b/bolt/unittests/Core/MCPlusBuilder.cpp index 9cdda5b..17bb686 100644 --- a/bolt/unittests/Core/MCPlusBuilder.cpp +++ b/bolt/unittests/Core/MCPlusBuilder.cpp @@ -141,7 +141,7 @@ TEST_P(MCPlusBuilderTester, Annotation) { BC->MIB->addEHInfo(Inst, MCPlus::MCLandingPad(LPSymbol, Value)); // Round-trip encoding-decoding check for negative values Optional EHInfo = BC->MIB->getEHInfo(Inst); - ASSERT_TRUE(EHInfo.hasValue()); + ASSERT_TRUE(EHInfo.has_value()); MCPlus::MCLandingPad LP = EHInfo.getValue(); uint64_t DecodedValue = LP.second; ASSERT_EQ(Value, DecodedValue); diff --git a/clang/lib/Driver/OffloadBundler.cpp b/clang/lib/Driver/OffloadBundler.cpp index 6e485c8..5aa4cb8 100644 --- a/clang/lib/Driver/OffloadBundler.cpp +++ b/clang/lib/Driver/OffloadBundler.cpp @@ -1185,7 +1185,7 @@ Error OffloadBundler::UnbundleArchive() { Optional OptionalCurBundleID = *CurBundleIDOrErr; // No device code in this child, skip. - if (!OptionalCurBundleID.hasValue()) + if (!OptionalCurBundleID) continue; StringRef CodeObject = *OptionalCurBundleID; diff --git a/mlir/examples/toy/Ch1/include/toy/AST.h b/mlir/examples/toy/Ch1/include/toy/AST.h index 95bcd67..f3a30fc 100644 --- a/mlir/examples/toy/Ch1/include/toy/AST.h +++ b/mlir/examples/toy/Ch1/include/toy/AST.h @@ -135,7 +135,7 @@ public: : ExprAST(Expr_Return, std::move(loc)), expr(std::move(expr)) {} llvm::Optional getExpr() { - if (expr.hasValue()) + if (expr.has_value()) return expr->get(); return llvm::None; } diff --git a/mlir/examples/toy/Ch1/parser/AST.cpp b/mlir/examples/toy/Ch1/parser/AST.cpp index 875b2e2..2eaabb1 100644 --- a/mlir/examples/toy/Ch1/parser/AST.cpp +++ b/mlir/examples/toy/Ch1/parser/AST.cpp @@ -155,7 +155,7 @@ void ASTDumper::dump(VariableExprAST *node) { void ASTDumper::dump(ReturnExprAST *node) { INDENT(); llvm::errs() << "Return\n"; - if (node->getExpr().hasValue()) + if (node->getExpr().has_value()) return dump(*node->getExpr()); { INDENT(); diff --git a/mlir/examples/toy/Ch2/include/toy/AST.h b/mlir/examples/toy/Ch2/include/toy/AST.h index 95bcd67..f3a30fc 100644 --- a/mlir/examples/toy/Ch2/include/toy/AST.h +++ b/mlir/examples/toy/Ch2/include/toy/AST.h @@ -135,7 +135,7 @@ public: : ExprAST(Expr_Return, std::move(loc)), expr(std::move(expr)) {} llvm::Optional getExpr() { - if (expr.hasValue()) + if (expr.has_value()) return expr->get(); return llvm::None; } diff --git a/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp index d929da8..167c807 100644 --- a/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp @@ -220,7 +220,7 @@ private: // 'return' takes an optional expression, handle that case here. mlir::Value expr = nullptr; - if (ret.getExpr().hasValue()) { + if (ret.getExpr().has_value()) { if (!(expr = mlirGen(*ret.getExpr().value()))) return mlir::failure(); } diff --git a/mlir/examples/toy/Ch2/parser/AST.cpp b/mlir/examples/toy/Ch2/parser/AST.cpp index 875b2e2..2eaabb1 100644 --- a/mlir/examples/toy/Ch2/parser/AST.cpp +++ b/mlir/examples/toy/Ch2/parser/AST.cpp @@ -155,7 +155,7 @@ void ASTDumper::dump(VariableExprAST *node) { void ASTDumper::dump(ReturnExprAST *node) { INDENT(); llvm::errs() << "Return\n"; - if (node->getExpr().hasValue()) + if (node->getExpr().has_value()) return dump(*node->getExpr()); { INDENT(); diff --git a/mlir/examples/toy/Ch3/include/toy/AST.h b/mlir/examples/toy/Ch3/include/toy/AST.h index 95bcd67..f3a30fc 100644 --- a/mlir/examples/toy/Ch3/include/toy/AST.h +++ b/mlir/examples/toy/Ch3/include/toy/AST.h @@ -135,7 +135,7 @@ public: : ExprAST(Expr_Return, std::move(loc)), expr(std::move(expr)) {} llvm::Optional getExpr() { - if (expr.hasValue()) + if (expr.has_value()) return expr->get(); return llvm::None; } diff --git a/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp index d929da8..167c807 100644 --- a/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp @@ -220,7 +220,7 @@ private: // 'return' takes an optional expression, handle that case here. mlir::Value expr = nullptr; - if (ret.getExpr().hasValue()) { + if (ret.getExpr().has_value()) { if (!(expr = mlirGen(*ret.getExpr().value()))) return mlir::failure(); } diff --git a/mlir/examples/toy/Ch3/parser/AST.cpp b/mlir/examples/toy/Ch3/parser/AST.cpp index 875b2e2..2eaabb1 100644 --- a/mlir/examples/toy/Ch3/parser/AST.cpp +++ b/mlir/examples/toy/Ch3/parser/AST.cpp @@ -155,7 +155,7 @@ void ASTDumper::dump(VariableExprAST *node) { void ASTDumper::dump(ReturnExprAST *node) { INDENT(); llvm::errs() << "Return\n"; - if (node->getExpr().hasValue()) + if (node->getExpr().has_value()) return dump(*node->getExpr()); { INDENT(); diff --git a/mlir/examples/toy/Ch4/include/toy/AST.h b/mlir/examples/toy/Ch4/include/toy/AST.h index 95bcd67..f3a30fc 100644 --- a/mlir/examples/toy/Ch4/include/toy/AST.h +++ b/mlir/examples/toy/Ch4/include/toy/AST.h @@ -135,7 +135,7 @@ public: : ExprAST(Expr_Return, std::move(loc)), expr(std::move(expr)) {} llvm::Optional getExpr() { - if (expr.hasValue()) + if (expr.has_value()) return expr->get(); return llvm::None; } diff --git a/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp index 7bc9080..0d586e0 100644 --- a/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp @@ -224,7 +224,7 @@ private: // 'return' takes an optional expression, handle that case here. mlir::Value expr = nullptr; - if (ret.getExpr().hasValue()) { + if (ret.getExpr().has_value()) { if (!(expr = mlirGen(*ret.getExpr().value()))) return mlir::failure(); } diff --git a/mlir/examples/toy/Ch4/parser/AST.cpp b/mlir/examples/toy/Ch4/parser/AST.cpp index 875b2e2..2eaabb1 100644 --- a/mlir/examples/toy/Ch4/parser/AST.cpp +++ b/mlir/examples/toy/Ch4/parser/AST.cpp @@ -155,7 +155,7 @@ void ASTDumper::dump(VariableExprAST *node) { void ASTDumper::dump(ReturnExprAST *node) { INDENT(); llvm::errs() << "Return\n"; - if (node->getExpr().hasValue()) + if (node->getExpr().has_value()) return dump(*node->getExpr()); { INDENT(); diff --git a/mlir/examples/toy/Ch5/include/toy/AST.h b/mlir/examples/toy/Ch5/include/toy/AST.h index 95bcd67..f3a30fc 100644 --- a/mlir/examples/toy/Ch5/include/toy/AST.h +++ b/mlir/examples/toy/Ch5/include/toy/AST.h @@ -135,7 +135,7 @@ public: : ExprAST(Expr_Return, std::move(loc)), expr(std::move(expr)) {} llvm::Optional getExpr() { - if (expr.hasValue()) + if (expr.has_value()) return expr->get(); return llvm::None; } diff --git a/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp index 7bc9080..0d586e0 100644 --- a/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp @@ -224,7 +224,7 @@ private: // 'return' takes an optional expression, handle that case here. mlir::Value expr = nullptr; - if (ret.getExpr().hasValue()) { + if (ret.getExpr().has_value()) { if (!(expr = mlirGen(*ret.getExpr().value()))) return mlir::failure(); } diff --git a/mlir/examples/toy/Ch5/parser/AST.cpp b/mlir/examples/toy/Ch5/parser/AST.cpp index 875b2e2..2eaabb1 100644 --- a/mlir/examples/toy/Ch5/parser/AST.cpp +++ b/mlir/examples/toy/Ch5/parser/AST.cpp @@ -155,7 +155,7 @@ void ASTDumper::dump(VariableExprAST *node) { void ASTDumper::dump(ReturnExprAST *node) { INDENT(); llvm::errs() << "Return\n"; - if (node->getExpr().hasValue()) + if (node->getExpr().has_value()) return dump(*node->getExpr()); { INDENT(); diff --git a/mlir/examples/toy/Ch6/include/toy/AST.h b/mlir/examples/toy/Ch6/include/toy/AST.h index 95bcd67..f3a30fc 100644 --- a/mlir/examples/toy/Ch6/include/toy/AST.h +++ b/mlir/examples/toy/Ch6/include/toy/AST.h @@ -135,7 +135,7 @@ public: : ExprAST(Expr_Return, std::move(loc)), expr(std::move(expr)) {} llvm::Optional getExpr() { - if (expr.hasValue()) + if (expr.has_value()) return expr->get(); return llvm::None; } diff --git a/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp index 7bc9080..0d586e0 100644 --- a/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp @@ -224,7 +224,7 @@ private: // 'return' takes an optional expression, handle that case here. mlir::Value expr = nullptr; - if (ret.getExpr().hasValue()) { + if (ret.getExpr().has_value()) { if (!(expr = mlirGen(*ret.getExpr().value()))) return mlir::failure(); } diff --git a/mlir/examples/toy/Ch6/parser/AST.cpp b/mlir/examples/toy/Ch6/parser/AST.cpp index 875b2e2..2eaabb1 100644 --- a/mlir/examples/toy/Ch6/parser/AST.cpp +++ b/mlir/examples/toy/Ch6/parser/AST.cpp @@ -155,7 +155,7 @@ void ASTDumper::dump(VariableExprAST *node) { void ASTDumper::dump(ReturnExprAST *node) { INDENT(); llvm::errs() << "Return\n"; - if (node->getExpr().hasValue()) + if (node->getExpr().has_value()) return dump(*node->getExpr()); { INDENT(); diff --git a/mlir/examples/toy/Ch7/include/toy/AST.h b/mlir/examples/toy/Ch7/include/toy/AST.h index 10f8256..665b8d5 100644 --- a/mlir/examples/toy/Ch7/include/toy/AST.h +++ b/mlir/examples/toy/Ch7/include/toy/AST.h @@ -155,7 +155,7 @@ public: : ExprAST(Expr_Return, std::move(loc)), expr(std::move(expr)) {} llvm::Optional getExpr() { - if (expr.hasValue()) + if (expr.has_value()) return expr->get(); return llvm::None; } diff --git a/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp index 2fcf8cc..8f2420c 100644 --- a/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp @@ -357,7 +357,7 @@ private: // 'return' takes an optional expression, handle that case here. mlir::Value expr = nullptr; - if (ret.getExpr().hasValue()) { + if (ret.getExpr().has_value()) { if (!(expr = mlirGen(*ret.getExpr().value()))) return mlir::failure(); } diff --git a/mlir/examples/toy/Ch7/parser/AST.cpp b/mlir/examples/toy/Ch7/parser/AST.cpp index 5ee5c4e..3542f8f 100644 --- a/mlir/examples/toy/Ch7/parser/AST.cpp +++ b/mlir/examples/toy/Ch7/parser/AST.cpp @@ -168,7 +168,7 @@ void ASTDumper::dump(VariableExprAST *node) { void ASTDumper::dump(ReturnExprAST *node) { INDENT(); llvm::errs() << "Return\n"; - if (node->getExpr().hasValue()) + if (node->getExpr().has_value()) return dump(*node->getExpr()); { INDENT(); -- 2.7.4