[llvm] 94460f5 - Don't use Optional::hasValue (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 26 19:54:47 PDT 2022
Author: Kazu Hirata
Date: 2022-06-26T19:54:41-07:00
New Revision: 94460f513654da2ee6e759db2804e73001818de5
URL: https://github.com/llvm/llvm-project/commit/94460f513654da2ee6e759db2804e73001818de5
DIFF: https://github.com/llvm/llvm-project/commit/94460f513654da2ee6e759db2804e73001818de5.diff
LOG: Don't use Optional::hasValue (NFC)
This patch replaces x.hasValue() with x where x is contextually
convertible to bool.
Added:
Modified:
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
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
index 1efd88d7cbb95..b2579e9ea615f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
@@ -817,7 +817,7 @@ void NotNullTerminatedResultCheck::check(
++It;
}
- if (AreSafeFunctionsWanted.hasValue())
+ if (AreSafeFunctionsWanted)
UseSafeFunctions = AreSafeFunctionsWanted.getValue();
}
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 3bade14f86b91..edafb40ff2b79 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -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;
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp
index fa6c70b4acbc4..4d9db8888c773 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -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();
diff --git a/clang-tools-extra/clangd/FeatureModule.cpp b/clang-tools-extra/clangd/FeatureModule.cpp
index 85977aadd6e32..872cea1443789 100644
--- a/clang-tools-extra/clangd/FeatureModule.cpp
+++ b/clang-tools-extra/clangd/FeatureModule.cpp
@@ -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;
}
diff --git a/clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp b/clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
index fbf07aad4cd1f..f7a3f2ae16ad3 100644
--- a/clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
+++ b/clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
@@ -338,7 +338,7 @@ TEST(GlobalCompilationDatabaseTest, CompileFlagsDirectory) {
}
MATCHER_P(hasArg, Flag, "") {
- if (!arg.hasValue()) {
+ if (!arg) {
*result_listener << "command is null";
return false;
}
diff --git a/clang-tools-extra/pseudo/lib/GLR.cpp b/clang-tools-extra/pseudo/lib/GLR.cpp
index 1cee8f86e599d..d93f682afac6c 100644
--- a/clang-tools-extra/pseudo/lib/GLR.cpp
+++ b/clang-tools-extra/pseudo/lib/GLR.cpp
@@ -375,11 +375,11 @@ class GLRReduce {
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;
diff --git a/clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp b/clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
index 970ffcebd717b..b8f50bf34bed4 100644
--- a/clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
@@ -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);
}
diff --git a/clang-tools-extra/unittests/clang-tidy/NamespaceAliaserTest.cpp b/clang-tools-extra/unittests/clang-tidy/NamespaceAliaserTest.cpp
index e4cd74ede7e4a..aa51231d363da 100644
--- a/clang-tools-extra/unittests/clang-tidy/NamespaceAliaserTest.cpp
+++ b/clang-tools-extra/unittests/clang-tidy/NamespaceAliaserTest.cpp
@@ -34,7 +34,7 @@ class InsertAliasCheck : public ClangTidyCheck {
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(
diff --git a/clang-tools-extra/unittests/clang-tidy/UsingInserterTest.cpp b/clang-tools-extra/unittests/clang-tidy/UsingInserterTest.cpp
index 71c71596d0d90..edd644c452d33 100644
--- a/clang-tools-extra/unittests/clang-tidy/UsingInserterTest.cpp
+++ b/clang-tools-extra/unittests/clang-tidy/UsingInserterTest.cpp
@@ -37,7 +37,7 @@ class InsertUsingCheck : public clang::tidy::ClangTidyCheck {
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")
diff --git a/clang/include/clang/APINotes/Types.h b/clang/include/clang/APINotes/Types.h
index ed5250f3d5b4e..d5372902ee095 100644
--- a/clang/include/clang/APINotes/Types.h
+++ b/clang/include/clang/APINotes/Types.h
@@ -77,7 +77,7 @@ class CommonEntityInfo {
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 &);
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 8735f4d9f4d46..aa688d9dda3c6 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -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();
diff --git a/polly/lib/Transform/ManualOptimizer.cpp b/polly/lib/Transform/ManualOptimizer.cpp
index ef705eca8740c..640ae0a859af8 100644
--- a/polly/lib/Transform/ManualOptimizer.cpp
+++ b/polly/lib/Transform/ManualOptimizer.cpp
@@ -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"))
diff --git a/polly/lib/Transform/MatmulOptimizer.cpp b/polly/lib/Transform/MatmulOptimizer.cpp
index 4a40fac0d03be..bad05dfb8ebfa 100644
--- a/polly/lib/Transform/MatmulOptimizer.cpp
+++ b/polly/lib/Transform/MatmulOptimizer.cpp
@@ -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
More information about the llvm-commits
mailing list