Don't use Optional::hasValue (NFC)
authorKazu Hirata <kazu@google.com>
Mon, 27 Jun 2022 02:54:41 +0000 (19:54 -0700)
committerKazu Hirata <kazu@google.com>
Mon, 27 Jun 2022 02:54:41 +0000 (19:54 -0700)
This patch replaces x.hasValue() with x where x is contextually
convertible to bool.

13 files changed:
clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/FeatureModule.cpp
clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
clang-tools-extra/pseudo/lib/GLR.cpp
clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
clang-tools-extra/unittests/clang-tidy/NamespaceAliaserTest.cpp
clang-tools-extra/unittests/clang-tidy/UsingInserterTest.cpp
clang/include/clang/APINotes/Types.h
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
polly/lib/Transform/ManualOptimizer.cpp
polly/lib/Transform/MatmulOptimizer.cpp

index 1efd88d7cbb955206a9a50625eee7334eba597f2..b2579e9ea615fb578a675975ae15d27e5b6cdba1 100644 (file)
@@ -817,7 +817,7 @@ void NotNullTerminatedResultCheck::check(
       ++It;
     }
 
-    if (AreSafeFunctionsWanted.hasValue())
+    if (AreSafeFunctionsWanted)
       UseSafeFunctions = AreSafeFunctionsWanted.getValue();
   }
 
index 3bade14f86b9104b32ef9e1a63504d7bfaa319d3..edafb40ff2b79557c0163979bba90d37c3df2266 100644 (file)
@@ -663,7 +663,7 @@ void ClangdLSPServer::onDocumentDidOpen(
 void ClangdLSPServer::onDocumentDidChange(
     const DidChangeTextDocumentParams &Params) {
   auto WantDiags = WantDiagnostics::Auto;
-  if (Params.wantDiagnostics.hasValue())
+  if (Params.wantDiagnostics)
     WantDiags = Params.wantDiagnostics.getValue() ? WantDiagnostics::Yes
                                                   : WantDiagnostics::No;
 
index fa6c70b4acbc4346b2b70b458d165ceacffcbb70..4d9db8888c773508fb71e7bb6344d60b87692f74 100644 (file)
@@ -411,7 +411,7 @@ void ClangdServer::codeComplete(PathRef File, Position Pos,
       clang::clangd::trace::Span Tracer("Completion results callback");
       CB(std::move(Result));
     }
-    if (SpecFuzzyFind && SpecFuzzyFind->NewReq.hasValue()) {
+    if (SpecFuzzyFind && SpecFuzzyFind->NewReq) {
       std::lock_guard<std::mutex> Lock(CachedCompletionFuzzyFindRequestMutex);
       CachedCompletionFuzzyFindRequestByFile[File] =
           SpecFuzzyFind->NewReq.getValue();
index 85977aadd6e3207eb5dfcfd2630c50b78c3721e8..872cea14437894679c5cf9887df9e26a3661252b 100644 (file)
@@ -13,12 +13,12 @@ namespace clang {
 namespace clangd {
 
 void FeatureModule::initialize(const Facilities &F) {
-  assert(!Fac.hasValue() && "Initialized twice");
+  assert(!Fac && "Initialized twice");
   Fac.emplace(F);
 }
 
 FeatureModule::Facilities &FeatureModule::facilities() {
-  assert(Fac.hasValue() && "Not initialized yet");
+  assert(Fac && "Not initialized yet");
   return *Fac;
 }
 
index fbf07aad4cd1ff1a24e76d768b5aaccf74b56606..f7a3f2ae16ad3cfdd60b2b8c9a8a26a22f0957f9 100644 (file)
@@ -338,7 +338,7 @@ TEST(GlobalCompilationDatabaseTest, CompileFlagsDirectory) {
 }
 
 MATCHER_P(hasArg, Flag, "") {
-  if (!arg.hasValue()) {
+  if (!arg) {
     *result_listener << "command is null";
     return false;
   }
index 1cee8f86e599ddbccb4be2b909209350d0b84f7e..d93f682afac6cf1b8f289f3cbd49dec82a6211af 100644 (file)
@@ -375,11 +375,11 @@ private:
     for (auto &A : Params.Table.getActions(Head->State, Lookahead)) {
       if (A.kind() != LRTable::Action::Reduce)
         continue;
-      if (RID.hasValue())
+      if (RID)
         return false;
       RID = A.getReduceRule();
     }
-    if (!RID.hasValue())
+    if (!RID)
       return true; // no reductions available, but we've processed the head!
     const auto &Rule = Params.G.lookupRule(*RID);
     const GSS::Node *Base = Head;
index 970ffcebd717b23603e8f8c8f5bc49de800fee39..b8f50bf34bed42acb88fee3bb75dd9b69f769323 100644 (file)
@@ -96,7 +96,7 @@ void CheckBaseInfo(Info *Expected, Info *Actual) {
 void CheckSymbolInfo(SymbolInfo *Expected, SymbolInfo *Actual) {
   CheckBaseInfo(Expected, Actual);
   EXPECT_EQ(Expected->DefLoc.hasValue(), Actual->DefLoc.hasValue());
-  if (Expected->DefLoc.hasValue() && Actual->DefLoc.hasValue()) {
+  if (Expected->DefLoc && Actual->DefLoc.hasValue()) {
     EXPECT_EQ(Expected->DefLoc->LineNumber, Actual->DefLoc->LineNumber);
     EXPECT_EQ(Expected->DefLoc->Filename, Actual->DefLoc->Filename);
   }
index e4cd74ede7e4a0a2b3a149db3712c4022c35bde5..aa51231d363da6d08ce53c5f83f036ce78903269 100644 (file)
@@ -34,7 +34,7 @@ public:
     assert(Call != nullptr && "Did not find node \"foo\"");
     auto Hint = Aliaser->createAlias(*Result.Context, *Call, "::foo::bar",
                                      {"b", "some_alias"});
-    if (Hint.hasValue())
+    if (Hint)
       diag(Call->getBeginLoc(), "Fix for testing") << Hint.getValue();
 
     diag(Call->getBeginLoc(), "insert call") << FixItHint::CreateInsertion(
index 71c71596d0d908bf67b8552e4823a92b5a6bbbda..edd644c452d33863bad7c5890e40d47854d8d54b 100644 (file)
@@ -37,7 +37,7 @@ public:
     auto Hint =
         Inserter->createUsingDeclaration(*Result.Context, *Call, "::foo::func");
 
-    if (Hint.hasValue())
+    if (Hint)
       diag(Call->getBeginLoc(), "Fix for testing") << Hint.getValue();
 
     diag(Call->getBeginLoc(), "insert call")
index ed5250f3d5b4e5c5703a69ae95a0975f0a78539e..d5372902ee095066c4655af4e0878e7cba1d399a 100644 (file)
@@ -77,7 +77,7 @@ public:
 
   void setSwiftPrivate(llvm::Optional<bool> Private) {
     SwiftPrivateSpecified = Private.hasValue();
-    SwiftPrivate = Private.hasValue() ? *Private : 0;
+    SwiftPrivate = Private ? *Private : 0;
   }
 
   friend bool operator==(const CommonEntityInfo &, const CommonEntityInfo &);
index 8735f4d9f4d46bbacd69b25b124cc7872ae98d96..aa688d9dda3c6d0173596591eb8882f0eef3e150 100644 (file)
@@ -24514,9 +24514,8 @@ bool DAGCombiner::mayAlias(SDNode *Op0, SDNode *Op1) const {
   auto &Size0 = MUC0.NumBytes;
   auto &Size1 = MUC1.NumBytes;
   if (OrigAlignment0 == OrigAlignment1 && SrcValOffset0 != SrcValOffset1 &&
-      Size0.hasValue() && Size1.hasValue() && *Size0 == *Size1 &&
-      OrigAlignment0 > *Size0 && SrcValOffset0 % *Size0 == 0 &&
-      SrcValOffset1 % *Size1 == 0) {
+      Size0 && Size1 && *Size0 == *Size1 && OrigAlignment0 > *Size0 &&
+      SrcValOffset0 % *Size0 == 0 && SrcValOffset1 % *Size1 == 0) {
     int64_t OffAlign0 = SrcValOffset0 % OrigAlignment0.value();
     int64_t OffAlign1 = SrcValOffset1 % OrigAlignment1.value();
 
index ef705eca8740c38b880b2431970a0e64c3098069..640ae0a859af8e8d693804610130e6ec57f3ccd2 100644 (file)
@@ -42,7 +42,7 @@ static TransformationMode hasUnrollTransformation(MDNode *LoopID) {
 
   Optional<int> Count =
       getOptionalIntLoopAttribute(LoopID, "llvm.loop.unroll.count");
-  if (Count.hasValue())
+  if (Count)
     return Count.getValue() == 1 ? TM_SuppressedByUser : TM_ForcedByUser;
 
   if (getBooleanLoopAttribute(LoopID, "llvm.loop.unroll.enable"))
index 4a40fac0d03be8350cf8d7397d3d56d1b2a9ee43..bad05dfb8ebfad2b96eea893458c2c79d62031c0 100644 (file)
@@ -570,19 +570,19 @@ static void getTargetCacheParameters(const llvm::TargetTransformInfo *TTI) {
   auto L1DCache = llvm::TargetTransformInfo::CacheLevel::L1D;
   auto L2DCache = llvm::TargetTransformInfo::CacheLevel::L2D;
   if (FirstCacheLevelSize == -1) {
-    if (TTI->getCacheSize(L1DCache).hasValue())
+    if (TTI->getCacheSize(L1DCache))
       FirstCacheLevelSize = TTI->getCacheSize(L1DCache).getValue();
     else
       FirstCacheLevelSize = static_cast<int>(FirstCacheLevelDefaultSize);
   }
   if (SecondCacheLevelSize == -1) {
-    if (TTI->getCacheSize(L2DCache).hasValue())
+    if (TTI->getCacheSize(L2DCache))
       SecondCacheLevelSize = TTI->getCacheSize(L2DCache).getValue();
     else
       SecondCacheLevelSize = static_cast<int>(SecondCacheLevelDefaultSize);
   }
   if (FirstCacheLevelAssociativity == -1) {
-    if (TTI->getCacheAssociativity(L1DCache).hasValue())
+    if (TTI->getCacheAssociativity(L1DCache))
       FirstCacheLevelAssociativity =
           TTI->getCacheAssociativity(L1DCache).getValue();
     else
@@ -590,7 +590,7 @@ static void getTargetCacheParameters(const llvm::TargetTransformInfo *TTI) {
           static_cast<int>(FirstCacheLevelDefaultAssociativity);
   }
   if (SecondCacheLevelAssociativity == -1) {
-    if (TTI->getCacheAssociativity(L2DCache).hasValue())
+    if (TTI->getCacheAssociativity(L2DCache))
       SecondCacheLevelAssociativity =
           TTI->getCacheAssociativity(L2DCache).getValue();
     else