diff --git a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h --- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h +++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h @@ -397,7 +397,7 @@ public: TrackConstraintBRVisitor(DefinedSVal constraint, bool assumption) : Constraint(constraint), Assumption(assumption), - IsZeroCheck(!Assumption && Constraint.getAs()) {} + IsZeroCheck(!Assumption && isa(Constraint)) {} void Profile(llvm::FoldingSetNodeID &ID) const override; diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h @@ -1183,7 +1183,7 @@ ElementRegion(QualType elementType, NonLoc Idx, const SubRegion *sReg) : TypedValueRegion(sReg, ElementRegionKind), ElementType(elementType), Index(Idx) { - assert((!Idx.getAs() || + assert((!isa(Idx) || Idx.castAs().getValue().isSigned()) && "The index must be signed"); assert(!elementType.isNull() && !elementType->isVoidType() && diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h @@ -727,7 +727,7 @@ if (Val.isUnknown()) return this; - assert(Val.getAs() && "Only NonLocs are supported!"); + assert(isa(Val) && "Only NonLocs are supported!"); return getStateManager().ConstraintMgr->assumeInclusiveRange( this, Val.castAs(), From, To, Assumption); @@ -740,7 +740,7 @@ if (Val.isUnknown()) return std::make_pair(this, this); - assert(Val.getAs() && "Only NonLocs are supported!"); + assert(isa(Val) && "Only NonLocs are supported!"); return getStateManager().ConstraintMgr->assumeInclusiveRangeDual( this, Val.castAs(), From, To); diff --git a/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp b/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp --- a/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp @@ -144,10 +144,9 @@ SVal extentBegin = computeExtentBegin(svalBuilder, rawOffset.getRegion()); if (Optional NV = extentBegin.getAs()) { - if (NV->getAs()) { + if (auto ConcreteNV = NV->getAs()) { std::pair simplifiedOffsets = - getSimplifiedOffsets(rawOffset.getByteOffset(), - NV->castAs(), + getSimplifiedOffsets(rawOffset.getByteOffset(), *ConcreteNV, svalBuilder); rawOffsetVal = simplifiedOffsets.first; *NV = simplifiedOffsets.second; @@ -180,13 +179,13 @@ // we are doing a load/store after the last valid offset. const MemRegion *MR = rawOffset.getRegion(); DefinedOrUnknownSVal Size = getDynamicExtent(state, MR, svalBuilder); - if (!Size.getAs()) + if (!isa(Size)) break; - if (Size.getAs()) { + if (auto ConcreteSize = Size.getAs()) { std::pair simplifiedOffsets = - getSimplifiedOffsets(rawOffset.getByteOffset(), - Size.castAs(), svalBuilder); + getSimplifiedOffsets(rawOffset.getByteOffset(), *ConcreteSize, + svalBuilder); rawOffsetVal = simplifiedOffsets.first; Size = simplifiedOffsets.second; } @@ -275,7 +274,7 @@ // is unknown or undefined, we lazily substitute '0'. Otherwise, // return 'val'. static inline SVal getValue(SVal val, SValBuilder &svalBuilder) { - return val.getAs() ? svalBuilder.makeArrayIndex(0) : val; + return val.isUndef() ? svalBuilder.makeZeroArrayIndex() : val; } // Scale a base value by a scaling factor, and return the scaled @@ -324,7 +323,7 @@ case MemRegion::ElementRegionKind: { const ElementRegion *elemReg = cast(region); SVal index = elemReg->getIndex(); - if (!index.getAs()) + if (!isa(index)) return RegionRawOffsetV2(); QualType elemType = elemReg->getElementType(); // If the element is an incomplete type, go no further. diff --git a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp --- a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp @@ -754,7 +754,7 @@ continue; // Ignore pointer constants. - if (msg.getArgSVal(I).getAs()) + if (isa(msg.getArgSVal(I))) continue; // Ignore pointer types annotated with 'NSObject' attribute. diff --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp @@ -696,7 +696,7 @@ NonLoc maxVal = svalBuilder.makeIntVal(maxValInt); SVal maxMinusRight; - if (right.getAs()) { + if (isa(right)) { maxMinusRight = svalBuilder.evalBinOpNN(state, BO_Sub, maxVal, right, sizeTy); } else { @@ -1675,7 +1675,7 @@ // amountCopied = min (size - dstLen - 1 , srcLen) SVal freeSpace = svalBuilder.evalBinOpNN(state, BO_Sub, *lenValNL, *dstStrLengthNL, sizeTy); - if (!freeSpace.getAs()) + if (!isa(freeSpace)) return; freeSpace = svalBuilder.evalBinOp(state, BO_Sub, freeSpace, diff --git a/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp @@ -248,7 +248,7 @@ DefinedOrUnknownSVal location = l.castAs(); // Check for null dereferences. - if (!location.getAs()) + if (!isa(location)) return; ProgramStateRef state = C.getState(); diff --git a/clang/lib/StaticAnalyzer/Checkers/GTestChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/GTestChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/GTestChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/GTestChecker.cpp @@ -135,7 +135,7 @@ SVal BooleanArgVal = Call->getArgSVal(0); if (IsRef) { // The argument is a reference, so load from it to get the boolean value. - if (!BooleanArgVal.getAs()) + if (!isa(BooleanArgVal)) return; BooleanArgVal = C.getState()->getSVal(BooleanArgVal.castAs()); } @@ -270,20 +270,17 @@ ProgramStateRef GTestChecker::assumeValuesEqual(SVal Val1, SVal Val2, ProgramStateRef State, CheckerContext &C) { - if (!Val1.getAs() || - !Val2.getAs()) + auto DVal1 = Val1.getAs(); + auto DVal2 = Val2.getAs(); + if (!DVal1.hasValue() || !DVal2.hasValue()) return State; auto ValuesEqual = - C.getSValBuilder().evalEQ(State, Val1.castAs(), - Val2.castAs()); - - if (!ValuesEqual.getAs()) + C.getSValBuilder().evalEQ(State, *DVal1, *DVal2).getAs(); + if (!ValuesEqual.hasValue()) return State; - State = C.getConstraintManager().assume( - State, ValuesEqual.castAs(), true); - + State = C.getConstraintManager().assume(State, *ValuesEqual, true); return State; } diff --git a/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp @@ -852,7 +852,7 @@ return; const auto WouldEscape = [](SVal V, QualType Ty) -> bool { - if (!V.getAs()) + if (!isa(V)) return false; const bool IsNonConstRef = Ty->isReferenceType() && !Ty.isConstQualified(); diff --git a/clang/lib/StaticAnalyzer/Checkers/Iterator.cpp b/clang/lib/StaticAnalyzer/Checkers/Iterator.cpp --- a/clang/lib/StaticAnalyzer/Checkers/Iterator.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/Iterator.cpp @@ -308,8 +308,8 @@ const auto comparison = SVB.evalBinOp(State, Opc, NL1, NL2, SVB.getConditionType()); - assert(comparison.getAs() && - "Symbol comparison must be a `DefinedSVal`"); + assert(isa(comparison) && + "Symbol comparison must be a `DefinedSVal`"); return !State->assume(comparison.castAs(), false); } diff --git a/clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp b/clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp --- a/clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp @@ -629,7 +629,7 @@ const Expr *Iterator, OverloadedOperatorKind OK, SVal Offset) const { - if (!Offset.getAs()) + if (!isa(Offset)) return; QualType PtrType = Iterator->getType(); @@ -799,8 +799,8 @@ SVB.evalBinOp(State, BO_EQ, nonloc::SymbolVal(Sym1), nonloc::SymbolVal(Sym2), SVB.getConditionType()); - assert(comparison.getAs() && - "Symbol comparison must be a `DefinedSVal`"); + assert(isa(comparison) && + "Symbol comparison must be a `DefinedSVal`"); auto NewState = State->assume(comparison.castAs(), Equal); if (!NewState) diff --git a/clang/lib/StaticAnalyzer/Checkers/MPI-Checker/MPIChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MPI-Checker/MPIChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/MPI-Checker/MPIChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/MPI-Checker/MPIChecker.cpp @@ -165,7 +165,7 @@ Ctx.getState(), SuperRegion, Ctx.getSValBuilder(), CE.getArgExpr(1)->getType()->getPointeeType()); const llvm::APSInt &ArrSize = - ElementCount.getAs()->getValue(); + ElementCount.castAs().getValue(); for (size_t i = 0; i < ArrSize; ++i) { const NonLoc Idx = Ctx.getSValBuilder().makeArrayIndex(i); diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -1182,7 +1182,7 @@ const Expr *FlagsEx = Call.getArgExpr(Call.getNumArgs() - 1); const SVal V = C.getSVal(FlagsEx); - if (!V.getAs()) { + if (!isa(V)) { // The case where 'V' can be a location can only be due to a bad header, // so in this case bail out. return None; @@ -1907,12 +1907,12 @@ return nullptr; SVal ArgVal = C.getSVal(ArgExpr); - if (!ArgVal.getAs()) + if (!isa(ArgVal)) return nullptr; DefinedOrUnknownSVal location = ArgVal.castAs(); // Check for null dereferences. - if (!location.getAs()) + if (!isa(location)) return nullptr; // The explicit NULL case, no operation is performed. @@ -2582,7 +2582,7 @@ const Expr *arg0Expr = CE->getArg(0); SVal Arg0Val = C.getSVal(arg0Expr); - if (!Arg0Val.getAs()) + if (!isa(Arg0Val)) return nullptr; DefinedOrUnknownSVal arg0Val = Arg0Val.castAs(); @@ -2598,7 +2598,7 @@ SVal TotalSize = C.getSVal(Arg1); if (SuffixWithN) TotalSize = evalMulForBufferSize(C, Arg1, CE->getArg(2)); - if (!TotalSize.getAs()) + if (!isa(TotalSize)) return nullptr; // Compare the size argument to 0. @@ -2908,7 +2908,7 @@ // Check arguments for being used after free. for (unsigned I = 0, E = Call.getNumArgs(); I != E; ++I) { SVal ArgSVal = Call.getArgSVal(I); - if (ArgSVal.getAs()) { + if (isa(ArgSVal)) { SymbolRef Sym = ArgSVal.getAsSymbol(); if (!Sym) continue; diff --git a/clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp @@ -48,8 +48,8 @@ CheckerContext &C) const { if (matchesAny(Call, MmapFn, MprotectFn)) { SVal ProtVal = Call.getArgSVal(2); - Optional ProtLoc = ProtVal.getAs(); - int64_t Prot = ProtLoc->getValue().getSExtValue(); + auto ProtLoc = ProtVal.castAs(); + int64_t Prot = ProtLoc.getValue().getSExtValue(); if (ProtExecOv != ProtExec) ProtExec = ProtExecOv; if (ProtReadOv != ProtRead) diff --git a/clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp @@ -214,7 +214,7 @@ CheckerContext &C) const { if (!isLoad) return; - if (loc.isUndef() || !loc.getAs()) + if (loc.isUndef() || !isa(loc)) return; ASTContext &Ctx = C.getASTContext(); diff --git a/clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp @@ -136,10 +136,10 @@ if (!DV) continue; - assert(!HasRefTypeParam || DV->getAs()); + assert(!HasRefTypeParam || isa(DV.getValue())); // Process the case when the argument is not a location. - if (ExpectedToBeNonNull && !DV->getAs()) { + if (ExpectedToBeNonNull && !isa(DV.getValue())) { // If the argument is a union type, we want to handle a potential // transparent_union GCC extension. if (!ArgE) @@ -161,7 +161,7 @@ assert(++CSV->begin() == CSV->end()); // FIXME: Handle (some_union){ some_other_union_val }, which turns into // a LazyCompoundVal inside a CompoundVal. - if (!V.getAs()) + if (!isa(V)) continue; // Retrieve the corresponding expression. diff --git a/clang/lib/StaticAnalyzer/Checkers/ObjCAtSyncChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/ObjCAtSyncChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/ObjCAtSyncChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/ObjCAtSyncChecker.cpp @@ -41,7 +41,7 @@ SVal V = C.getSVal(Ex); // Uninitialized value used for the mutex? - if (V.getAs()) { + if (isa(V)) { if (ExplodedNode *N = C.generateErrorNode()) { if (!BT_undef) BT_undef.reset(new BuiltinBug(this, "Uninitialized value used as mutex " diff --git a/clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp @@ -413,7 +413,7 @@ AnalysisDeclContext *analCtx = C.getCurrentAnalysisDeclContext(); if (!analCtx->getSelfDecl()) return false; - if (!location.getAs()) + if (!isa(location)) return false; loc::MemRegionVal MRV = location.castAs(); diff --git a/clang/lib/StaticAnalyzer/Checkers/STLAlgorithmModeling.cpp b/clang/lib/StaticAnalyzer/Checkers/STLAlgorithmModeling.cpp --- a/clang/lib/StaticAnalyzer/Checkers/STLAlgorithmModeling.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/STLAlgorithmModeling.cpp @@ -131,7 +131,7 @@ nonloc::SymbolVal(NewPos->getOffset()), nonloc::SymbolVal(Pos->getOffset()), SVB.getConditionType()); - assert(GreaterOrEqual.getAs() && + assert(isa(GreaterOrEqual) && "Symbol comparison must be a `DefinedSVal`"); StateFound = StateFound->assume(GreaterOrEqual.castAs(), true); } @@ -153,7 +153,7 @@ nonloc::SymbolVal(NewPos->getOffset()), nonloc::SymbolVal(Pos->getOffset()), SVB.getConditionType()); - assert(Less.getAs() && + assert(isa(Less) && "Symbol comparison must be a `DefinedSVal`"); StateFound = StateFound->assume(Less.castAs(), true); } diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp @@ -254,7 +254,7 @@ return State; DefinedOrUnknownSVal L = V.castAs(); - if (!L.getAs()) + if (!isa(L)) return State; return State->assume(L, CannotBeNull); diff --git a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp @@ -330,7 +330,7 @@ SVal V = State->getSVal(FieldVal); - if (isDereferencableType(T) || V.getAs()) { + if (isDereferencableType(T) || isa(V)) { if (isDereferencableUninit(FR, LocalChain)) ContainsUninitField = true; continue; diff --git a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp --- a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp @@ -141,10 +141,10 @@ SVal V = State->getSVal(FR); assert((isDereferencableType(FR->getDecl()->getType()) || - V.getAs()) && + isa(V)) && "This method only checks dereferenceable objects!"); - if (V.isUnknown() || V.getAs()) { + if (V.isUnknown() || isa(V)) { IsAnyFieldInitialized = true; return false; } @@ -230,8 +230,8 @@ // If the static type of the field is a void pointer, or it is a // nonloc::LocAsInteger, we need to cast it back to the dynamic type before // dereferencing. - bool NeedsCastBack = isVoidPointer(FR->getDecl()->getType()) || - V.getAs(); + bool NeedsCastBack = + isVoidPointer(FR->getDecl()->getType()) || isa(V); // The region we'd like to acquire. const auto *R = V.getAsRegion()->getAs(); diff --git a/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp @@ -227,7 +227,7 @@ // Now check if oflags has O_CREAT set. const Expr *oflagsEx = CE->getArg(FlagsArgIndex); const SVal V = C.getSVal(oflagsEx); - if (!V.getAs()) { + if (!isa(V)) { // The case where 'V' can be a location can only be due to a bad header, // so in this case bail out. return; diff --git a/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp @@ -278,8 +278,7 @@ if (!State) return; - auto ArraySizeNL = ArraySize.getAs(); - if (!ArraySizeNL) { + if (!isa(ArraySize)) { // Array size could not be determined but state may contain new assumptions. C.addTransition(State); return; @@ -289,7 +288,7 @@ if (VD) { State = setDynamicExtent(State, State->getRegion(VD, C.getLocationContext()), - ArraySize.castAs(), SVB); + ArraySize.castAs(), SVB); } // Remember our assumptions! diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp --- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -914,7 +914,7 @@ const SVal V) { AnalyzerOptions &Options = N->getState()->getAnalysisManager().options; if (EnableNullFPSuppression && Options.ShouldSuppressNullReturnPaths && - V.getAs()) + isa(V)) BR.addVisitor(R->getAs(), V); } @@ -1030,14 +1030,13 @@ if (RetE->isGLValue()) { if ((LValue = V.getAs())) { SVal RValue = State->getRawSVal(*LValue, RetE->getType()); - if (RValue.getAs()) + if (isa(RValue)) V = RValue; } } // Ignore aggregate rvalues. - if (V.getAs() || - V.getAs()) + if (isa(V)) return nullptr; RetE = RetE->IgnoreParenCasts(); @@ -1052,7 +1051,7 @@ bool WouldEventBeMeaningless = false; if (State->isNull(V).isConstrainedTrue()) { - if (V.getAs()) { + if (isa(V)) { // If we have counter-suppression enabled, make sure we keep visiting // future nodes. We want to emit a path note as well, in case @@ -1082,10 +1081,7 @@ if (N->getCFG().size() == 3) WouldEventBeMeaningless = true; - if (V.getAs()) - Out << "Returning pointer"; - else - Out << "Returning value"; + Out << (isa(V) ? "Returning pointer" : "Returning value"); } } @@ -1308,7 +1304,7 @@ llvm_unreachable("Unexpected store kind"); } - if (SI.Value.getAs()) { + if (isa(SI.Value)) { OS << Action << (isObjCPointer(SI.Dest) ? "nil" : "a null pointer value"); } else if (auto CVal = SI.Value.getAs()) { @@ -1351,7 +1347,7 @@ OS << "Passing "; - if (SI.Value.getAs()) { + if (isa(SI.Value)) { OS << (isObjCPointer(Param) ? "nil object reference" : "null pointer value"); @@ -1382,7 +1378,7 @@ StoreInfo SI) { const bool HasSuffix = SI.Dest->canPrintPretty(); - if (SI.Value.getAs()) { + if (isa(SI.Value)) { OS << (isObjCPointer(SI.Dest) ? "nil object reference stored" : (HasSuffix ? "Null pointer value stored" : "Storing null pointer value")); @@ -1680,7 +1676,7 @@ SmallString<64> sbuf; llvm::raw_svector_ostream os(sbuf); - if (Constraint.getAs()) { + if (isa(Constraint)) { os << "Assuming pointer value is "; os << (Assumption ? "non-null" : "null"); } diff --git a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp --- a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp +++ b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp @@ -680,7 +680,7 @@ return UnknownVal(); SVal ThisVal = getSVal(Base); - assert(ThisVal.isUnknownOrUndef() || ThisVal.getAs()); + assert(ThisVal.isUnknownOrUndef() || isa(ThisVal)); return ThisVal; } diff --git a/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp b/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp --- a/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp +++ b/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp @@ -127,10 +127,10 @@ if (LHSVal.isUnknownOrUndef()) return false; ProgramStateManager &Mgr = State->getStateManager(); - if (!LHSVal.getAs()) { + if (!isa(LHSVal)) { LHSVal = Mgr.getStoreManager().getBinding(State->getStore(), LHSVal.castAs()); - if (LHSVal.isUnknownOrUndef() || !LHSVal.getAs()) + if (LHSVal.isUnknownOrUndef() || !isa(LHSVal)) return false; } diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp --- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -304,7 +304,7 @@ if (!Result) { // If we don't have an explicit result expression, we're in "if needed" // mode. Only create a region if the current value is a NonLoc. - if (!InitValWithAdjustments.getAs()) { + if (!isa(InitValWithAdjustments)) { if (OutRegionWithAdjustments) *OutRegionWithAdjustments = nullptr; return State; @@ -313,7 +313,7 @@ } else { // We need to create a region no matter what. Make sure we don't try to // stuff a Loc into a non-pointer temporary region. - assert(!InitValWithAdjustments.getAs() || + assert(!isa(InitValWithAdjustments) || Loc::isLocType(Result->getType()) || Result->getType()->isMemberPointerType()); } @@ -2335,7 +2335,7 @@ llvm_unreachable("No block with label."); } - if (V.getAs() || V.getAs()) { + if (isa(V)) { // Dispatch to the first target and mark it as a sink. //ExplodedNode* N = builder.generateNode(builder.begin(), state, true); // FIXME: add checker visit. @@ -2886,7 +2886,7 @@ // If the location is not a 'Loc', it will already be handled by // the checkers. There is nothing left to do. - if (!location.getAs()) { + if (!isa(location)) { const ProgramPoint L = PostStore(StoreE, LC, /*Loc*/nullptr, /*tag*/nullptr); ProgramStateRef state = Pred->getState(); @@ -2956,7 +2956,7 @@ SVal location, const ProgramPointTag *tag, QualType LoadTy) { - assert(!location.getAs() && "location cannot be a NonLoc."); + assert(!isa(location) && "location cannot be a NonLoc."); assert(NodeEx); assert(BoundEx); // Evaluate the location (checks for bad dereferences). @@ -3087,7 +3087,7 @@ for (const Expr *O : A->outputs()) { SVal X = state->getSVal(O, Pred->getLocationContext()); - assert(!X.getAs()); // Should be an Lval, or unknown, undef. + assert(!isa(X)); // Should be an Lval, or unknown, undef. if (Optional LV = X.getAs()) state = state->bindLoc(*LV, UnknownVal(), Pred->getLocationContext()); diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp --- a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp @@ -29,8 +29,7 @@ SVal Symbol, SVal Other, Expr* Expression, SValBuilder &svalBuilder, unsigned Count, const LocationContext *LCtx) { QualType Ty = Expression->getType(); - if (Other.getAs() && - Ty->isIntegralOrEnumerationType() && + if (isa(Other) && Ty->isIntegralOrEnumerationType() && Symbol.isUnknown()) { return svalBuilder.conjureSymbolVal(Expression, LCtx, Ty, Count); } @@ -372,7 +371,7 @@ case CK_IntegralToPointer: case CK_PointerToIntegral: { SVal V = state->getSVal(Ex, LCtx); - if (V.getAs()) { + if (isa(V)) { state = state->BindExpr(CastE, LCtx, UnknownVal()); Bldr.generateNode(CastE, Pred, state); continue; diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp --- a/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp @@ -129,7 +129,7 @@ static SVal adjustReturnValue(SVal V, QualType ExpectedTy, QualType ActualTy, StoreManager &StoreMgr) { // For now, the only adjustments we handle apply only to locations. - if (!V.getAs()) + if (!isa(V)) return V; // If the types already match, don't do any unnecessary work. diff --git a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp --- a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp +++ b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp @@ -216,7 +216,7 @@ } ProgramStateRef ProgramState::killBinding(Loc LV) const { - assert(!LV.getAs() && "Use invalidateRegion instead."); + assert(!isa(LV) && "Use invalidateRegion instead."); Store OldStore = getStore(); const StoreRef &newStore = diff --git a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp --- a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp +++ b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp @@ -1361,10 +1361,10 @@ /// the array). This is called by ExprEngine when evaluating casts /// from arrays to pointers. SVal RegionStoreManager::ArrayToPointer(Loc Array, QualType T) { - if (Array.getAs()) + if (isa(Array)) return Array; - if (!Array.getAs()) + if (!isa(Array)) return UnknownVal(); const SubRegion *R = @@ -1378,8 +1378,8 @@ //===----------------------------------------------------------------------===// SVal RegionStoreManager::getBinding(RegionBindingsConstRef B, Loc L, QualType T) { - assert(!L.getAs() && "location unknown"); - assert(!L.getAs() && "location undefined"); + assert(!isa(L) && "location unknown"); + assert(!isa(L) && "location undefined"); // For access to concrete addresses, return UnknownVal. Checks // for null dereferences (and similar errors) are done by checkers, not @@ -1994,8 +1994,7 @@ // Lazy bindings are usually handled through getExistingLazyBinding(). // We should unify these two code paths at some point. - if (val.getAs() || - val.getAs()) + if (isa(val)) return val; llvm_unreachable("Unknown default value"); @@ -2414,7 +2413,7 @@ } // Handle lazy compound values. - if (Init.getAs()) + if (isa(Init)) return bindAggregate(B, R, Init); if (Init.isUnknown()) @@ -2459,13 +2458,13 @@ const VectorType *VT = T->castAs(); // Use castAs for typedefs. // Handle lazy compound values and symbolic values. - if (V.getAs() || V.getAs()) + if (isa(V)) return bindAggregate(B, R, V); // We may get non-CompoundVal accidentally due to imprecise cast logic or // that we are binding symbolic struct value. Kill the field values, and if // the value is symbolic go and bind it as a "default" binding. - if (!V.getAs()) { + if (!isa(V)) { return bindAggregate(B, R, UnknownVal()); } @@ -2551,13 +2550,13 @@ return *NewB; return bindAggregate(B, R, V); } - if (V.getAs()) + if (isa(V)) return bindAggregate(B, R, V); // We may get non-CompoundVal accidentally due to imprecise cast logic or // that we are binding symbolic struct value. Kill the field values, and if // the value is symbolic go and bind it as a "default" binding. - if (V.isUnknown() || !V.getAs()) + if (V.isUnknown() || !isa(V)) return bindAggregate(B, R, UnknownVal()); // The raw CompoundVal is essentially a symbolic InitListExpr: an (immutable) diff --git a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp --- a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp +++ b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp @@ -486,8 +486,7 @@ if (lhs.isUnknown() || rhs.isUnknown()) return UnknownVal(); - if (lhs.getAs() || - rhs.getAs()) { + if (isa(lhs) || isa(rhs)) { return UnknownVal(); } diff --git a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp --- a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp +++ b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp @@ -856,7 +856,7 @@ // This must come after the test if the RHS is a symbol, which is used to // build constraints. The address of any non-symbolic region is guaranteed // to be non-NULL, as is any label. - assert(rhs.getAs() || rhs.getAs()); + assert((isa(rhs))); if (lhs.isZeroConstant()) { switch (op) { default: diff --git a/clang/lib/StaticAnalyzer/Core/Store.cpp b/clang/lib/StaticAnalyzer/Core/Store.cpp --- a/clang/lib/StaticAnalyzer/Core/Store.cpp +++ b/clang/lib/StaticAnalyzer/Core/Store.cpp @@ -459,10 +459,10 @@ // FIXME: For absolute pointer addresses, we just return that value back as // well, although in reality we should return the offset added to that // value. See also the similar FIXME in getLValueFieldOrIvar(). - if (Base.isUnknownOrUndef() || Base.getAs()) + if (Base.isUnknownOrUndef() || isa(Base)) return Base; - if (Base.getAs()) + if (isa(Base)) return UnknownVal(); const SubRegion *BaseRegion = @@ -488,7 +488,7 @@ SVal BaseIdx = ElemR->getIndex(); - if (!BaseIdx.getAs()) + if (!isa(BaseIdx)) return UnknownVal(); const llvm::APSInt &BaseIdxI = @@ -497,7 +497,7 @@ // Only allow non-integer offsets if the base region has no offset itself. // FIXME: This is a somewhat arbitrary restriction. We should be using // SValBuilder here to add the two offsets without checking their types. - if (!Offset.getAs()) { + if (!isa(Offset)) { if (isa(BaseRegion->StripCasts())) return UnknownVal();