Skip to content

Commit 97afce0

Browse files
[clang] Don't use Optional::hasValue (NFC)
This patch replaces Optional::hasValue with the implicit cast to bool in conditionals only.
1 parent 0a0effd commit 97afce0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+104
-104
lines changed

clang/include/clang/Analysis/PathDiagnostic.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,8 @@ class PathDiagnosticEventPiece : public PathDiagnosticSpotPiece {
544544
/// flag may have been previously set, at which point it will not
545545
/// be reset unless one specifies to do so.
546546
void setPrunable(bool isPrunable, bool override = false) {
547-
if (IsPrunable.hasValue() && !override)
548-
return;
547+
if (IsPrunable && !override)
548+
return;
549549
IsPrunable = isPrunable;
550550
}
551551

clang/include/clang/Sema/Sema.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,9 +1766,9 @@ class Sema final {
17661766
template <typename T>
17671767
friend const SemaDiagnosticBuilder &
17681768
operator<<(const SemaDiagnosticBuilder &Diag, const T &Value) {
1769-
if (Diag.ImmediateDiag.hasValue())
1769+
if (Diag.ImmediateDiag)
17701770
*Diag.ImmediateDiag << Value;
1771-
else if (Diag.PartialDiagId.hasValue())
1771+
else if (Diag.PartialDiagId)
17721772
Diag.S.DeviceDeferredDiags[Diag.Fn][*Diag.PartialDiagId].second
17731773
<< Value;
17741774
return Diag;
@@ -1780,26 +1780,26 @@ class Sema final {
17801780
template <typename T, typename = typename std::enable_if<
17811781
!std::is_lvalue_reference<T>::value>::type>
17821782
const SemaDiagnosticBuilder &operator<<(T &&V) const {
1783-
if (ImmediateDiag.hasValue())
1783+
if (ImmediateDiag)
17841784
*ImmediateDiag << std::move(V);
1785-
else if (PartialDiagId.hasValue())
1785+
else if (PartialDiagId)
17861786
S.DeviceDeferredDiags[Fn][*PartialDiagId].second << std::move(V);
17871787
return *this;
17881788
}
17891789

17901790
friend const SemaDiagnosticBuilder &
17911791
operator<<(const SemaDiagnosticBuilder &Diag, const PartialDiagnostic &PD) {
1792-
if (Diag.ImmediateDiag.hasValue())
1792+
if (Diag.ImmediateDiag)
17931793
PD.Emit(*Diag.ImmediateDiag);
1794-
else if (Diag.PartialDiagId.hasValue())
1794+
else if (Diag.PartialDiagId)
17951795
Diag.S.DeviceDeferredDiags[Diag.Fn][*Diag.PartialDiagId].second = PD;
17961796
return Diag;
17971797
}
17981798

17991799
void AddFixItHint(const FixItHint &Hint) const {
1800-
if (ImmediateDiag.hasValue())
1800+
if (ImmediateDiag)
18011801
ImmediateDiag->AddFixItHint(Hint);
1802-
else if (PartialDiagId.hasValue())
1802+
else if (PartialDiagId)
18031803
S.DeviceDeferredDiags[Fn][*PartialDiagId].second.AddFixItHint(Hint);
18041804
}
18051805

clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ class SMTConstraintManager : public clang::ento::SimpleConstraintManager {
341341
addStateConstraints(NewState);
342342

343343
Optional<bool> res = Solver->check();
344-
if (!res.hasValue())
344+
if (!res)
345345
Cached[hash] = ConditionTruthVal();
346346
else
347347
Cached[hash] = ConditionTruthVal(res.getValue());

clang/lib/AST/AttrImpl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,23 +168,23 @@ OMPDeclareTargetDeclAttr::getActiveAttr(const ValueDecl *VD) {
168168
llvm::Optional<OMPDeclareTargetDeclAttr::MapTypeTy>
169169
OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(const ValueDecl *VD) {
170170
llvm::Optional<OMPDeclareTargetDeclAttr *> ActiveAttr = getActiveAttr(VD);
171-
if (ActiveAttr.hasValue())
171+
if (ActiveAttr)
172172
return ActiveAttr.getValue()->getMapType();
173173
return llvm::None;
174174
}
175175

176176
llvm::Optional<OMPDeclareTargetDeclAttr::DevTypeTy>
177177
OMPDeclareTargetDeclAttr::getDeviceType(const ValueDecl *VD) {
178178
llvm::Optional<OMPDeclareTargetDeclAttr *> ActiveAttr = getActiveAttr(VD);
179-
if (ActiveAttr.hasValue())
179+
if (ActiveAttr)
180180
return ActiveAttr.getValue()->getDevType();
181181
return llvm::None;
182182
}
183183

184184
llvm::Optional<SourceLocation>
185185
OMPDeclareTargetDeclAttr::getLocation(const ValueDecl *VD) {
186186
llvm::Optional<OMPDeclareTargetDeclAttr *> ActiveAttr = getActiveAttr(VD);
187-
if (ActiveAttr.hasValue())
187+
if (ActiveAttr)
188188
return ActiveAttr.getValue()->getRange().getBegin();
189189
return llvm::None;
190190
}

clang/lib/ASTMatchers/Dynamic/Parser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,9 @@ bool Parser::parseIdentifierPrefixImpl(VariantValue *Value) {
397397
assert(NamedValue.isMatcher());
398398
llvm::Optional<DynTypedMatcher> Result =
399399
NamedValue.getMatcher().getSingleMatcher();
400-
if (Result.hasValue()) {
400+
if (Result) {
401401
llvm::Optional<DynTypedMatcher> Bound = Result->tryBind(BindID);
402-
if (Bound.hasValue()) {
402+
if (Bound) {
403403
*Value = VariantMatcher::SingleMatcher(*Bound);
404404
return true;
405405
}

clang/lib/ASTMatchers/Dynamic/Registry.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,9 +797,9 @@ VariantMatcher Registry::constructBoundMatcher(MatcherCtor Ctor,
797797
if (Out.isNull()) return Out;
798798

799799
llvm::Optional<DynTypedMatcher> Result = Out.getSingleMatcher();
800-
if (Result.hasValue()) {
800+
if (Result) {
801801
llvm::Optional<DynTypedMatcher> Bound = Result->tryBind(BindID);
802-
if (Bound.hasValue()) {
802+
if (Bound) {
803803
return VariantMatcher::SingleMatcher(*Bound);
804804
}
805805
}

clang/lib/Analysis/BodyFarm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ static Stmt *create_OSAtomicCompareAndSwap(ASTContext &C, const FunctionDecl *D)
697697

698698
Stmt *BodyFarm::getBody(const FunctionDecl *D) {
699699
Optional<Stmt *> &Val = Bodies[D];
700-
if (Val.hasValue())
700+
if (Val)
701701
return Val.getValue();
702702

703703
Val = nullptr;
@@ -872,7 +872,7 @@ Stmt *BodyFarm::getBody(const ObjCMethodDecl *D) {
872872
return nullptr;
873873

874874
Optional<Stmt *> &Val = Bodies[D];
875-
if (Val.hasValue())
875+
if (Val)
876876
return Val.getValue();
877877
Val = nullptr;
878878

clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ buildStmtToBasicBlockMap(const CFG &Cfg) {
3333

3434
for (const CFGElement &Element : *Block) {
3535
auto Stmt = Element.getAs<CFGStmt>();
36-
if (!Stmt.hasValue())
36+
if (!Stmt)
3737
continue;
3838

3939
StmtToBlock[Stmt.getValue().getStmt()] = Block;

clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class StmtToEnvMapImpl : public StmtToEnvMap {
5050
auto BlockIT = CFCtx.getStmtToBlock().find(&ignoreCFGOmittedNodes(S));
5151
assert(BlockIT != CFCtx.getStmtToBlock().end());
5252
const auto &State = BlockToState[BlockIT->getSecond()->getBlockID()];
53-
assert(State.hasValue());
53+
assert(State);
5454
return &State.getValue().Env;
5555
}
5656

@@ -209,7 +209,7 @@ static TypeErasedDataflowAnalysisState computeBlockInputState(
209209
// loop back edge to `Block`.
210210
const llvm::Optional<TypeErasedDataflowAnalysisState> &MaybePredState =
211211
BlockStates[Pred->getBlockID()];
212-
if (!MaybePredState.hasValue())
212+
if (!MaybePredState)
213213
continue;
214214

215215
TypeErasedDataflowAnalysisState PredState = MaybePredState.getValue();
@@ -222,14 +222,14 @@ static TypeErasedDataflowAnalysisState computeBlockInputState(
222222
}
223223
}
224224

225-
if (MaybeState.hasValue()) {
225+
if (MaybeState) {
226226
Analysis.joinTypeErased(MaybeState->Lattice, PredState.Lattice);
227227
MaybeState->Env.join(PredState.Env, Analysis);
228228
} else {
229229
MaybeState = std::move(PredState);
230230
}
231231
}
232-
if (!MaybeState.hasValue()) {
232+
if (!MaybeState) {
233233
// FIXME: Consider passing `Block` to `Analysis.typeErasedInitialElement()`
234234
// to enable building analyses like computation of dominators that
235235
// initialize the state of each basic block differently.
@@ -367,7 +367,7 @@ runTypeErasedDataflowAnalysis(const ControlFlowContext &CFCtx,
367367
TypeErasedDataflowAnalysisState NewBlockState =
368368
transferBlock(CFCtx, BlockStates, *Block, InitEnv, Analysis);
369369

370-
if (OldBlockState.hasValue() &&
370+
if (OldBlockState &&
371371
Analysis.isEqualTypeErased(OldBlockState.getValue().Lattice,
372372
NewBlockState.Lattice) &&
373373
OldBlockState->Env.equivalentTo(NewBlockState.Env, Analysis)) {

clang/lib/Analysis/PathDiagnostic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ static Optional<bool> comparePath(const PathPieces &X, const PathPieces &Y) {
319319

320320
for ( ; X_I != X_end && Y_I != Y_end; ++X_I, ++Y_I) {
321321
Optional<bool> b = comparePiece(**X_I, **Y_I);
322-
if (b.hasValue())
322+
if (b)
323323
return b.getValue();
324324
}
325325

@@ -396,7 +396,7 @@ static bool compare(const PathDiagnostic &X, const PathDiagnostic &Y) {
396396
return (*XI) < (*YI);
397397
}
398398
Optional<bool> b = comparePath(X.path, Y.path);
399-
assert(b.hasValue());
399+
assert(b);
400400
return b.getValue();
401401
}
402402

clang/lib/Analysis/UninitializedValues.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class CFGBlockValues {
148148
Value getValue(const CFGBlock *block, const CFGBlock *dstBlock,
149149
const VarDecl *vd) {
150150
const Optional<unsigned> &idx = declToIndex.getValueIndex(vd);
151-
assert(idx.hasValue());
151+
assert(idx);
152152
return getValueVector(block)[idx.getValue()];
153153
}
154154
};
@@ -209,7 +209,7 @@ void CFGBlockValues::resetScratch() {
209209

210210
ValueVector::reference CFGBlockValues::operator[](const VarDecl *vd) {
211211
const Optional<unsigned> &idx = declToIndex.getValueIndex(vd);
212-
assert(idx.hasValue());
212+
assert(idx);
213213
return scratch[idx.getValue()];
214214
}
215215

clang/lib/Basic/Targets/RISCV.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ bool RISCVTargetInfo::hasFeature(StringRef Feature) const {
251251
.Case("riscv64", Is64Bit)
252252
.Case("64bit", Is64Bit)
253253
.Default(None);
254-
if (Result.hasValue())
254+
if (Result)
255255
return Result.getValue();
256256

257257
if (ISAInfo->isSupportedExtensionFeature(Feature))

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2826,12 +2826,12 @@ bool CodeGenModule::isProfileInstrExcluded(llvm::Function *Fn,
28262826
CodeGenOptions::ProfileInstrKind Kind = getCodeGenOpts().getProfileInstr();
28272827
// First, check the function name.
28282828
Optional<bool> V = ProfileList.isFunctionExcluded(Fn->getName(), Kind);
2829-
if (V.hasValue())
2829+
if (V)
28302830
return *V;
28312831
// Next, check the source location.
28322832
if (Loc.isValid()) {
28332833
Optional<bool> V = ProfileList.isLocationExcluded(Loc, Kind);
2834-
if (V.hasValue())
2834+
if (V)
28352835
return *V;
28362836
}
28372837
// If location is unknown, this may be a compiler-generated function. Assume

clang/lib/Driver/ToolChains/AVR.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ void AVR::Linker::ConstructJob(Compilation &C, const JobAction &JA,
475475
D.Diag(diag::warn_drv_avr_stdlib_not_linked);
476476
}
477477

478-
if (SectionAddressData.hasValue()) {
478+
if (SectionAddressData) {
479479
std::string DataSectionArg = std::string("-Tdata=0x") +
480480
llvm::utohexstr(SectionAddressData.getValue());
481481
CmdArgs.push_back(Args.MakeArgString(DataSectionArg));

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2086,7 +2086,7 @@ void Generic_GCC::GCCInstallationDetector::print(raw_ostream &OS) const {
20862086
}
20872087

20882088
bool Generic_GCC::GCCInstallationDetector::getBiarchSibling(Multilib &M) const {
2089-
if (BiarchSibling.hasValue()) {
2089+
if (BiarchSibling) {
20902090
M = BiarchSibling.getValue();
20912091
return true;
20922092
}

clang/lib/Edit/RewriteObjCFoundationAPI.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -725,11 +725,11 @@ static bool getLiteralInfo(SourceRange literalRange,
725725
break;
726726
}
727727

728-
if (!UpperU.hasValue() && !UpperL.hasValue())
728+
if (!UpperU && !UpperL)
729729
UpperU = UpperL = true;
730-
else if (UpperU.hasValue() && !UpperL.hasValue())
730+
else if (UpperU && !UpperL)
731731
UpperL = UpperU;
732-
else if (UpperL.hasValue() && !UpperU.hasValue())
732+
else if (UpperL && !UpperU)
733733
UpperU = UpperL;
734734

735735
Info.U = *UpperU ? "U" : "u";

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,7 +1951,7 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
19511951
<< "-fdiagnostics-hotness-threshold=";
19521952
} else {
19531953
Opts.DiagnosticsHotnessThreshold = *ResultOrErr;
1954-
if ((!Opts.DiagnosticsHotnessThreshold.hasValue() ||
1954+
if ((!Opts.DiagnosticsHotnessThreshold ||
19551955
Opts.DiagnosticsHotnessThreshold.getValue() > 0) &&
19561956
!UsingProfile)
19571957
Diags.Report(diag::warn_drv_diagnostics_hotness_requires_pgo)
@@ -1968,7 +1968,7 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
19681968
<< "-fdiagnostics-misexpect-tolerance=";
19691969
} else {
19701970
Opts.DiagnosticsMisExpectTolerance = *ResultOrErr;
1971-
if ((!Opts.DiagnosticsMisExpectTolerance.hasValue() ||
1971+
if ((!Opts.DiagnosticsMisExpectTolerance ||
19721972
Opts.DiagnosticsMisExpectTolerance.getValue() > 0) &&
19731973
!UsingProfile)
19741974
Diags.Report(diag::warn_drv_diagnostics_misexpect_requires_pgo)
@@ -2578,10 +2578,10 @@ static void GenerateFrontendArgs(const FrontendOptions &Opts,
25782578
for (const auto &ModuleFile : Opts.ModuleFiles)
25792579
GenerateArg(Args, OPT_fmodule_file, ModuleFile, SA);
25802580

2581-
if (Opts.AuxTargetCPU.hasValue())
2581+
if (Opts.AuxTargetCPU)
25822582
GenerateArg(Args, OPT_aux_target_cpu, *Opts.AuxTargetCPU, SA);
25832583

2584-
if (Opts.AuxTargetFeatures.hasValue())
2584+
if (Opts.AuxTargetFeatures)
25852585
for (const auto &Feature : *Opts.AuxTargetFeatures)
25862586
GenerateArg(Args, OPT_aux_target_feature, Feature, SA);
25872587

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,11 +831,11 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
831831
VersionTuple tuple = LangOpts.ObjCRuntime.getVersion();
832832

833833
unsigned minor = 0;
834-
if (tuple.getMinor().hasValue())
834+
if (tuple.getMinor())
835835
minor = tuple.getMinor().getValue();
836836

837837
unsigned subminor = 0;
838-
if (tuple.getSubminor().hasValue())
838+
if (tuple.getSubminor())
839839
subminor = tuple.getSubminor().getValue();
840840

841841
Builder.defineMacro("__OBJFW_RUNTIME_ABI__",

clang/lib/Lex/DependencyDirectivesScanner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ Scanner::tryLexIdentifierOrSkipLine(const char *&First, const char *const End) {
549549

550550
StringRef Scanner::lexIdentifier(const char *&First, const char *const End) {
551551
Optional<StringRef> Id = tryLexIdentifierOrSkipLine(First, End);
552-
assert(Id.hasValue() && "expected identifier token");
552+
assert(Id && "expected identifier token");
553553
return Id.getValue();
554554
}
555555

clang/lib/Lex/MacroInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ MacroDirective::DefInfo MacroDirective::getDefinition() {
209209
}
210210

211211
VisibilityMacroDirective *VisMD = cast<VisibilityMacroDirective>(MD);
212-
if (!isPublic.hasValue())
212+
if (!isPublic)
213213
isPublic = VisMD->isPublic();
214214
}
215215

clang/lib/Lex/PPMacroExpansion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,7 @@ static void EvaluateFeatureLikeBuiltinMacro(llvm::raw_svector_ostream& OS,
13251325

13261326
// The last ')' has been reached; return the value if one found or
13271327
// a diagnostic and a dummy value.
1328-
if (Result.hasValue()) {
1328+
if (Result) {
13291329
OS << Result.getValue();
13301330
// For strict conformance to __has_cpp_attribute rules, use 'L'
13311331
// suffix for dated literals.

clang/lib/Lex/PreprocessingRecord.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ bool PreprocessingRecord::isEntityInFileID(iterator PPEI, FileID FID) {
114114
// deserializing it.
115115
Optional<bool> IsInFile =
116116
ExternalSource->isPreprocessedEntityInFileID(LoadedIndex, FID);
117-
if (IsInFile.hasValue())
117+
if (IsInFile)
118118
return IsInFile.getValue();
119119

120120
// The external source did not provide a definite answer, go and deserialize

clang/lib/Parse/ParseOpenMP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1873,7 +1873,7 @@ void Parser::ParseOMPDeclareTargetClauses(
18731873
if (IsDeviceTypeClause) {
18741874
Optional<SimpleClauseData> DevTypeData =
18751875
parseOpenMPSimpleClause(*this, OMPC_device_type);
1876-
if (DevTypeData.hasValue()) {
1876+
if (DevTypeData) {
18771877
if (DeviceTypeLoc.isValid()) {
18781878
// We already saw another device_type clause, diagnose it.
18791879
Diag(DevTypeData.getValue().Loc,

clang/lib/Sema/SemaCUDA.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ bool Sema::inferCUDATargetForImplicitSpecialMember(CXXRecordDecl *ClassDecl,
444444
// If no target was inferred, mark this member as __host__ __device__;
445445
// it's the least restrictive option that can be invoked from any target.
446446
bool NeedsH = true, NeedsD = true;
447-
if (InferredTarget.hasValue()) {
447+
if (InferredTarget) {
448448
if (InferredTarget.getValue() == CFT_Device)
449449
NeedsH = false;
450450
else if (InferredTarget.getValue() == CFT_Host)

clang/lib/Sema/SemaChecking.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1873,7 +1873,7 @@ static ExprResult SemaBuiltinLaunder(Sema &S, CallExpr *TheCall) {
18731873
return 2;
18741874
return llvm::Optional<unsigned>{};
18751875
}();
1876-
if (DiagSelect.hasValue()) {
1876+
if (DiagSelect) {
18771877
S.Diag(TheCall->getBeginLoc(), diag::err_builtin_launder_invalid_arg)
18781878
<< DiagSelect.getValue() << TheCall->getSourceRange();
18791879
return ExprError();

0 commit comments

Comments
 (0)