[clang] Don't use Optional::hasValue (NFC)

This commit is contained in:
Kazu Hirata 2022-06-20 10:51:34 -07:00
parent 8254966062
commit 452db157c9
41 changed files with 62 additions and 62 deletions

View File

@ -676,7 +676,7 @@ public:
if (!HasFlagEnum && HasFlagEnum)
setFlagEnum(RHS.isFlagEnum());
if (!EnumExtensibility.hasValue())
if (!EnumExtensibility)
EnumExtensibility = RHS.EnumExtensibility;
return *this;
@ -706,7 +706,7 @@ public:
TypedefInfo &operator|=(const TypedefInfo &RHS) {
static_cast<CommonTypeInfo &>(*this) |= RHS;
if (!SwiftWrapper.hasValue())
if (!SwiftWrapper)
SwiftWrapper = RHS.SwiftWrapper;
return *this;
}

View File

@ -2554,7 +2554,7 @@ public:
bool IsParam) const {
auto SubTnullability = SubT->getNullability(*this);
auto SuperTnullability = SuperT->getNullability(*this);
if (SubTnullability.hasValue() == SuperTnullability.hasValue()) {
if (SubTnullability.has_value() == SuperTnullability.has_value()) {
// Neither has nullability; return true
if (!SubTnullability)
return true;

View File

@ -671,7 +671,7 @@ let Class = TemplateSpecializationType in {
def : Creator<[{
QualType result;
if (!underlyingType.hasValue()) {
if (!underlyingType) {
result = ctx.getCanonicalTemplateSpecializationType(templateName,
templateArguments);
} else {

View File

@ -129,7 +129,7 @@ public:
// Constraints are unsatisfiable
Optional<bool> isSat = Solver->check();
if (!isSat.hasValue() || !isSat.getValue())
if (!isSat || !*isSat)
return nullptr;
// Model does not assign interpretation
@ -146,7 +146,7 @@ public:
Solver->addConstraint(NotExp);
Optional<bool> isNotSat = Solver->check();
if (!isNotSat.hasValue() || isNotSat.getValue())
if (!isNotSat || *isNotSat)
return nullptr;
// This is the only solution, store it

View File

@ -25,7 +25,7 @@ using namespace trans;
ASTTraverser::~ASTTraverser() { }
bool MigrationPass::CFBridgingFunctionsDefined() {
if (!EnableCFBridgeFns.hasValue())
if (!EnableCFBridgeFns)
EnableCFBridgeFns = SemaRef.isKnownName("CFBridgingRetain") &&
SemaRef.isKnownName("CFBridgingRelease");
return *EnableCFBridgeFns;

View File

@ -696,7 +696,7 @@ ExprDependence clang::computeDependence(CXXNewExpr *E) {
E->getAllocatedTypeSourceInfo()->getType()->getDependence());
D |= toExprDependenceForImpliedType(E->getAllocatedType()->getDependence());
auto Size = E->getArraySize();
if (Size.hasValue() && *Size)
if (Size && *Size)
D |= turnTypeToValueDependence((*Size)->getDependence());
if (auto *I = E->getInitializer())
D |= turnTypeToValueDependence(I->getDependence());

View File

@ -284,7 +284,7 @@ public:
~LocalScope() override { this->emitDestruction(); }
void addLocal(const Scope::Local &Local) override {
if (!Idx.hasValue()) {
if (!Idx) {
Idx = this->Ctx->Descriptors.size();
this->Ctx->Descriptors.emplace_back();
}
@ -293,7 +293,7 @@ public:
}
void emitDestruction() override {
if (!Idx.hasValue())
if (!Idx)
return;
this->Ctx->emitDestroy(*Idx, SourceInfo{});
}

View File

@ -917,7 +917,7 @@ Parser::parseMatcherExpression(StringRef &Code, Sema *S,
}
llvm::Optional<DynTypedMatcher> Result =
Value.getMatcher().getSingleMatcher();
if (!Result.hasValue()) {
if (!Result) {
Error->addError(SourceRange(), Error->ET_ParserOverloadedType)
<< Value.getTypeAsString();
}

View File

@ -345,7 +345,7 @@ static unsigned scanFromBlock(const CFGBlock *Start,
if (!UB)
break;
if (!TreatAllSuccessorsAsReachable.hasValue()) {
if (!TreatAllSuccessorsAsReachable) {
assert(PP);
TreatAllSuccessorsAsReachable =
shouldTreatSuccessorsAsReachable(item, *PP);

View File

@ -741,7 +741,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
assert(!CodeGenOpts.hasProfileCSIRUse() &&
"Cannot have both CSProfileUse pass and CSProfileGen pass at "
"the same time");
if (PGOOpt.hasValue()) {
if (PGOOpt) {
assert(PGOOpt->Action != PGOOptions::IRInstr &&
PGOOpt->Action != PGOOptions::SampleUse &&
"Cannot run CSProfileGen pass with ProfileGen or SampleUse "

View File

@ -80,7 +80,7 @@ public:
InlinedShareds(CGF) {
if (EmitPreInitStmt)
emitPreInitStmt(CGF, S);
if (!CapturedRegion.hasValue())
if (!CapturedRegion)
return;
assert(S.hasAssociatedStmt() &&
"Expected associated statement for inlined directive.");

View File

@ -392,7 +392,7 @@ public:
else if (I.isPPIfElse() || I.isEmptyLine())
SR = {SM, LocStart, LocEnd};
if (!SR.hasValue())
if (!SR)
continue;
auto Region = CounterMappingRegion::makeSkipped(
*CovFileID, SR->LineStart, SR->ColumnStart, SR->LineEnd,
@ -587,7 +587,7 @@ struct CounterCoverageMappingBuilder
Optional<SourceLocation> EndLoc = None,
Optional<Counter> FalseCount = None) {
if (StartLoc && !FalseCount.hasValue()) {
if (StartLoc && !FalseCount) {
MostRecentLocation = *StartLoc;
}

View File

@ -31,7 +31,7 @@ std::vector<std::string> scanDirectory(StringRef Path) {
End = fs::directory_iterator();
!EC && It != End; It.increment(EC)) {
auto status = getFileStatus(It->path());
if (!status.hasValue())
if (!status)
continue;
Result.emplace_back(sys::path::filename(It->path()));
}

View File

@ -390,7 +390,7 @@ void AVRToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
// Omit if there is no avr-libc installed.
Optional<std::string> AVRLibcRoot = findAVRLibcInstallation();
if (!AVRLibcRoot.hasValue())
if (!AVRLibcRoot)
return;
// Add 'avr-libc/include' to clang system include paths if applicable.

View File

@ -295,7 +295,7 @@ static Optional<StringRef> findSimilarStr(
for (StringRef C : Candidates) {
size_t CurDist = LHS.edit_distance(C, true);
if (CurDist <= MaxDist) {
if (!SimilarStr.hasValue()) {
if (!SimilarStr) {
// The first similar string found.
SimilarStr = {C, CurDist};
} else if (CurDist < SimilarStr->second) {
@ -305,7 +305,7 @@ static Optional<StringRef> findSimilarStr(
}
}
if (SimilarStr.hasValue()) {
if (SimilarStr) {
return SimilarStr->first;
} else {
return None;

View File

@ -1311,7 +1311,7 @@ already_lexed:
case tok::l_paren:
++ParenDepth;
if (Result.hasValue())
if (Result)
break;
if (!SuppressDiagnostic) {
PP.Diag(Tok.getLocation(), diag::err_pp_nested_paren) << II;
@ -1341,7 +1341,7 @@ already_lexed:
default: {
// Parse the macro argument, if one not found so far.
if (Result.hasValue())
if (Result)
break;
bool HasLexedNextToken = false;

View File

@ -295,7 +295,7 @@ void TokenLexer::ExpandFunctionArguments() {
// the closing r_paren of the __VA_OPT__.
if (!Tokens[I].is(tok::r_paren) || !VCtx.sawClosingParen()) {
// Lazily expand __VA_ARGS__ when we see the first __VA_OPT__.
if (!CalledWithVariadicArguments.hasValue()) {
if (!CalledWithVariadicArguments) {
CalledWithVariadicArguments =
ActualArgs->invokedWithVariadicArgument(Macro, PP);
}

View File

@ -1835,7 +1835,7 @@ void Parser::ParseOMPDeclareTargetClauses(
bool IsIndirectClause = getLangOpts().OpenMP >= 51 &&
getOpenMPClauseKind(ClauseName) == OMPC_indirect;
if (DTCI.Indirect.hasValue() && IsIndirectClause) {
if (DTCI.Indirect && IsIndirectClause) {
Diag(Tok, diag::err_omp_more_one_clause)
<< getOpenMPDirectiveName(OMPD_declare_target)
<< getOpenMPClauseName(OMPC_indirect) << 0;
@ -1933,7 +1933,7 @@ void Parser::ParseOMPDeclareTargetClauses(
ConsumeToken();
}
if (DTCI.Indirect.hasValue() && DTCI.DT != OMPDeclareTargetDeclAttr::DT_Any)
if (DTCI.Indirect && DTCI.DT != OMPDeclareTargetDeclAttr::DT_Any)
Diag(DeviceTypeLoc, diag::err_omp_declare_target_indirect_device_type);
// For declare target require at least 'to' or 'link' to be present.

View File

@ -377,7 +377,7 @@ bool Sema::inferCUDATargetForImplicitSpecialMember(CXXRecordDecl *ClassDecl,
continue;
CUDAFunctionTarget BaseMethodTarget = IdentifyCUDATarget(SMOR.getMethod());
if (!InferredTarget.hasValue()) {
if (!InferredTarget) {
InferredTarget = BaseMethodTarget;
} else {
bool ResolutionError = resolveCalleeCUDATargetConflict(
@ -421,7 +421,7 @@ bool Sema::inferCUDATargetForImplicitSpecialMember(CXXRecordDecl *ClassDecl,
CUDAFunctionTarget FieldMethodTarget =
IdentifyCUDATarget(SMOR.getMethod());
if (!InferredTarget.hasValue()) {
if (!InferredTarget) {
InferredTarget = FieldMethodTarget;
} else {
bool ResolutionError = resolveCalleeCUDATargetConflict(

View File

@ -5645,7 +5645,7 @@ void Sema::CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base,
// Objective-C property reference. Bail if we're performing fix-it code
// completion since Objective-C properties are normally backed by ivars,
// most Objective-C fix-its here would have little value.
if (AccessOpFixIt.hasValue()) {
if (AccessOpFixIt) {
return false;
}
AddedPropertiesSet AddedProperties;
@ -5670,7 +5670,7 @@ void Sema::CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base,
// Objective-C instance variable access. Bail if we're performing fix-it
// code completion since Objective-C properties are normally backed by
// ivars, most Objective-C fix-its here would have little value.
if (AccessOpFixIt.hasValue()) {
if (AccessOpFixIt) {
return false;
}
ObjCInterfaceDecl *Class = nullptr;

View File

@ -19119,7 +19119,7 @@ Sema::FunctionEmissionStatus Sema::getEmissionStatus(FunctionDecl *FD,
// be ommitted.
Optional<OMPDeclareTargetDeclAttr::DevTypeTy> DevTy =
OMPDeclareTargetDeclAttr::getDeviceType(FD->getCanonicalDecl());
if (DevTy.hasValue())
if (DevTy)
if (*DevTy == OMPDeclareTargetDeclAttr::DT_NoHost)
return FunctionEmissionStatus::OMPDiscarded;
}

View File

@ -4537,7 +4537,7 @@ static QualType mergeTypeNullabilityForRedecl(Sema &S, SourceLocation loc,
auto prevNullability = prevType->getNullability(S.Context);
// Easy case: both have nullability.
if (nullability.hasValue() == prevNullability.hasValue()) {
if (nullability.has_value() == prevNullability.has_value()) {
// Neither has nullability; continue.
if (!nullability)
return type;

View File

@ -3540,7 +3540,7 @@ public:
!Stack->isImplicitTaskFirstprivate(VD))
return;
// Skip allocators in uses_allocators clauses.
if (Stack->isUsesAllocatorsDecl(VD).hasValue())
if (Stack->isUsesAllocatorsDecl(VD))
return;
DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, /*FromParent=*/false);
@ -8049,7 +8049,7 @@ bool OpenMPIterationSpaceChecker::checkAndSetCond(Expr *S) {
CE->getArg(1), CE->getSourceRange(), CE->getOperatorLoc());
}
}
if (Res.hasValue())
if (Res)
return *Res;
if (dependent() || SemaRef.CurContext->isDependentContext())
return false;
@ -22183,7 +22183,7 @@ static void checkDeclInTargetContext(SourceLocation SL, SourceRange SR,
return;
}
}
if (MapTy.hasValue())
if (MapTy)
return;
SemaRef.Diag(VD->getLocation(), diag::warn_omp_not_in_target_context);
SemaRef.Diag(SL, diag::note_used_here) << SR;

View File

@ -12525,7 +12525,7 @@ Sema::resolveAddressOfSingleOverloadCandidate(Expr *E, DeclAccessPair &Pair) {
// We skipped over some ambiguous declarations which might be ambiguous with
// the selected result.
for (FunctionDecl *Skipped : AmbiguousDecls)
if (!CheckMoreConstrained(Skipped, Result).hasValue())
if (!CheckMoreConstrained(Skipped, Result))
return nullptr;
Pair = DAP;
}

View File

@ -2306,7 +2306,7 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) {
if (PP.isRecordingPreamble() && PP.hasRecordedPreamble()) {
assert(!IsModule);
auto SkipInfo = PP.getPreambleSkipInfo();
if (SkipInfo.hasValue()) {
if (SkipInfo) {
Record.push_back(true);
AddSourceLocation(SkipInfo->HashTokenLoc, Record);
AddSourceLocation(SkipInfo->IfTokenLoc, Record);

View File

@ -260,7 +260,7 @@ SVal GTestChecker::getAssertionResultSuccessFieldValue(
Optional<Loc> FieldLoc =
State->getLValue(SuccessField, Instance).getAs<Loc>();
if (!FieldLoc.hasValue())
if (!FieldLoc)
return UnknownVal();
return State->getSVal(*FieldLoc);

View File

@ -1005,7 +1005,7 @@ NonLocalizedStringBRVisitor::VisitNode(const ExplodedNode *Succ,
return nullptr;
Optional<StmtPoint> Point = Succ->getLocation().getAs<StmtPoint>();
if (!Point.hasValue())
if (!Point)
return nullptr;
auto *LiteralExpr = dyn_cast<ObjCStringLiteral>(Point->getStmt());

View File

@ -1155,7 +1155,7 @@ MallocChecker::performKernelMalloc(const CallEvent &Call, CheckerContext &C,
ASTContext &Ctx = C.getASTContext();
llvm::Triple::OSType OS = Ctx.getTargetInfo().getTriple().getOS();
if (!KernelZeroFlagVal.hasValue()) {
if (!KernelZeroFlagVal) {
if (OS == llvm::Triple::FreeBSD)
KernelZeroFlagVal = 0x0100;
else if (OS == llvm::Triple::NetBSD)
@ -2218,7 +2218,7 @@ void MallocChecker::HandleNonHeapDealloc(CheckerContext &C, SVal ArgVal,
}
Optional<MallocChecker::CheckKind> CheckKind = getCheckIfTracked(Family);
if (!CheckKind.hasValue())
if (!CheckKind)
return;
if (ExplodedNode *N = C.generateErrorNode()) {
@ -2351,7 +2351,7 @@ void MallocChecker::HandleOffsetFree(CheckerContext &C, SVal ArgVal,
}
Optional<MallocChecker::CheckKind> CheckKind = getCheckIfTracked(Family);
if (!CheckKind.hasValue())
if (!CheckKind)
return;
ExplodedNode *N = C.generateErrorNode();
@ -2408,7 +2408,7 @@ void MallocChecker::HandleUseAfterFree(CheckerContext &C, SourceRange Range,
}
Optional<MallocChecker::CheckKind> CheckKind = getCheckIfTracked(C, Sym);
if (!CheckKind.hasValue())
if (!CheckKind)
return;
if (ExplodedNode *N = C.generateErrorNode()) {
@ -2447,7 +2447,7 @@ void MallocChecker::HandleDoubleFree(CheckerContext &C, SourceRange Range,
}
Optional<MallocChecker::CheckKind> CheckKind = getCheckIfTracked(C, Sym);
if (!CheckKind.hasValue())
if (!CheckKind)
return;
if (ExplodedNode *N = C.generateErrorNode()) {
@ -2477,7 +2477,7 @@ void MallocChecker::HandleDoubleDelete(CheckerContext &C, SymbolRef Sym) const {
}
Optional<MallocChecker::CheckKind> CheckKind = getCheckIfTracked(C, Sym);
if (!CheckKind.hasValue())
if (!CheckKind)
return;
if (ExplodedNode *N = C.generateErrorNode()) {
@ -2505,7 +2505,7 @@ void MallocChecker::HandleUseZeroAlloc(CheckerContext &C, SourceRange Range,
Optional<MallocChecker::CheckKind> CheckKind = getCheckIfTracked(C, Sym);
if (!CheckKind.hasValue())
if (!CheckKind)
return;
if (ExplodedNode *N = C.generateErrorNode()) {
@ -2537,7 +2537,7 @@ void MallocChecker::HandleFunctionPtrFree(CheckerContext &C, SVal ArgVal,
}
Optional<MallocChecker::CheckKind> CheckKind = getCheckIfTracked(Family);
if (!CheckKind.hasValue())
if (!CheckKind)
return;
if (ExplodedNode *N = C.generateErrorNode()) {
@ -2750,7 +2750,7 @@ void MallocChecker::HandleLeak(SymbolRef Sym, ExplodedNode *N,
Optional<MallocChecker::CheckKind>
CheckKind = getCheckIfTracked(Family, true);
if (!CheckKind.hasValue())
if (!CheckKind)
return;
assert(N);

View File

@ -69,7 +69,7 @@ void StringChecker::checkPreCall(const CallEvent &Call,
if (!isCharToStringCtor(Call, C.getASTContext()))
return;
const auto Param = Call.getArgSVal(0).getAs<Loc>();
if (!Param.hasValue())
if (!Param)
return;
// We managed to constrain the parameter to non-null.

View File

@ -211,7 +211,7 @@ void UnixAPIMisuseChecker::CheckOpenVariant(CheckerContext &C,
// The definition of O_CREAT is platform specific. We need a better way
// of querying this information from the checking environment.
if (!Val_O_CREAT.hasValue()) {
if (!Val_O_CREAT) {
if (C.getASTContext().getTargetInfo().getTriple().getVendor()
== llvm::Triple::Apple)
Val_O_CREAT = 0x0200;

View File

@ -1883,7 +1883,7 @@ static bool optimizeEdges(const PathDiagnosticConstruct &C, PathPieces &path,
lexicalContains(PM, s1Start, s1End)) {
SourceRange EdgeRange(PieceI->getEndLocation().asLocation(),
PieceI->getStartLocation().asLocation());
if (!getLengthOnSingleLine(SM, EdgeRange).hasValue())
if (!getLengthOnSingleLine(SM, EdgeRange))
removeEdge = true;
}
}

View File

@ -3077,7 +3077,7 @@ bool ConditionBRVisitor::printValue(const Expr *CondVarExpr, raw_ostream &Out,
if (!IsAssuming)
IntValue = getConcreteIntegerValue(CondVarExpr, N);
if (IsAssuming || !IntValue.hasValue()) {
if (IsAssuming || !IntValue) {
if (Ty->isBooleanType())
Out << (TookTrue ? "true" : "false");
else

View File

@ -86,7 +86,7 @@ bool ento::CallDescription::matchesImpl(const FunctionDecl *Callee,
(!RequiredParams || *RequiredParams <= ParamCount);
}
if (!II.hasValue()) {
if (!II) {
II = &FD->getASTContext().Idents.get(getFunctionName());
}

View File

@ -772,7 +772,7 @@ void CXXInstanceCall::getInitialStackFrameContents(
// FIXME: CallEvent maybe shouldn't be directly accessing StoreManager.
Optional<SVal> V =
StateMgr.getStoreManager().evalBaseToDerived(ThisVal, Ty);
if (!V.hasValue()) {
if (!V) {
// We might have suffered some sort of placement new earlier, so
// we're constructing in a completely unexpected storage.
// Fall back to a generic pointer cast for this-value.
@ -1192,7 +1192,7 @@ lookupRuntimeDefinition(const ObjCInterfaceDecl *Interface,
PMC[{Interface, LookupSelector, InstanceMethod}];
// Query lookupPrivateMethod() if the cache does not hit.
if (!Val.hasValue()) {
if (!Val) {
Val = Interface->lookupPrivateMethod(LookupSelector, InstanceMethod);
if (!*Val) {

View File

@ -389,7 +389,7 @@ void PlistPrinter::ReportMacroExpansions(raw_ostream &o, unsigned indent) {
const Optional<StringRef> ExpansionText =
getExpandedMacro(MacroExpansionLoc, CTU, MacroExpansions, SM);
if (!MacroName.hasValue() || !ExpansionText.hasValue())
if (!MacroName || !ExpansionText)
continue;
Indent(o, indent) << "<dict>\n";

View File

@ -2500,7 +2500,7 @@ RegionStoreManager::bindArray(RegionBindingsConstRef B,
// If the init list is shorter than the array length (or the array has
// variable length), set the array default value. Values that are already set
// are not overwritten.
if (!Size.hasValue() || i < Size.getValue())
if (!Size || i < *Size)
NewB = setImplicitDefaultValue(NewB, R, ElementTy);
return NewB;

View File

@ -240,7 +240,7 @@ public:
std::unique_ptr<FrontendAction> Action;
if (ModuleName.hasValue())
if (ModuleName)
Action = std::make_unique<GetDependenciesByModuleNameAction>(*ModuleName);
else
Action = std::make_unique<ReadPCHAndPreprocessAction>();
@ -317,7 +317,7 @@ llvm::Error DependencyScanningWorker::computeDependencies(
Files ? Files : new FileManager(FileSystemOptions(), RealFS);
Optional<std::vector<std::string>> ModifiedCommandLine;
if (ModuleName.hasValue()) {
if (ModuleName) {
ModifiedCommandLine = CommandLine;
InMemoryFS->addFile(*ModuleName, 0, llvm::MemoryBuffer::getMemBuffer(""));
ModifiedCommandLine->emplace_back(*ModuleName);

View File

@ -278,7 +278,7 @@ public:
return llvm::make_error<StringError>(errc::invalid_argument,
"Id not bound: " + BaseId);
llvm::Optional<std::string> S = tooling::buildAccess(*E, *Match.Context);
if (!S.hasValue())
if (!S)
return llvm::make_error<StringError>(
errc::invalid_argument,
"Could not construct object text from ID: " + BaseId);

View File

@ -1255,7 +1255,7 @@ static Error UnbundleArchive() {
Optional<StringRef> OptionalCurBundleID = *CurBundleIDOrErr;
// No device code in this child, skip.
if (!OptionalCurBundleID.hasValue())
if (!OptionalCurBundleID)
continue;
StringRef CodeObject = *OptionalCurBundleID;

View File

@ -325,7 +325,7 @@ bool InferPedantic::isOffByDefault(const Record *Diag) {
bool InferPedantic::groupInPedantic(const Record *Group, bool increment) {
GMap::mapped_type &V = GroupCount[Group];
// Lazily compute the threshold value for the group count.
if (!V.second.hasValue()) {
if (!V.second) {
const GroupInfo &GI =
DiagsInGroup[std::string(Group->getValueAsString("GroupName"))];
V.second = GI.SubGroups.size() + GI.DiagsInGroup.size();

View File

@ -467,7 +467,7 @@ void RVVEmitter::createRVVIntrinsics(
Optional<RVVTypes> Types =
RVVType::computeTypes(BT, Log2LMUL, NF, Prototype);
// Ignored to create new intrinsic if there are any illegal types.
if (!Types.hasValue())
if (!Types)
continue;
auto SuffixStr = RVVIntrinsic::getSuffixStr(BT, Log2LMUL, SuffixDesc);