steakhal created this revision. steakhal added reviewers: martong, NoQ. Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun. Herald added a reviewer: Szelethus. Herald added a project: All. steakhal requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Depends on D125709 <https://reviews.llvm.org/D125709> Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D127742 Files: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp clang/lib/StaticAnalyzer/Checkers/GTestChecker.cpp clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp clang/lib/StaticAnalyzer/Checkers/Iterator.cpp clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp clang/lib/StaticAnalyzer/Checkers/MPI-Checker/MPIChecker.cpp clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp clang/lib/StaticAnalyzer/Checkers/ObjCAtSyncChecker.cpp clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp clang/lib/StaticAnalyzer/Checkers/STLAlgorithmModeling.cpp clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp clang/lib/StaticAnalyzer/Core/CallEvent.cpp clang/lib/StaticAnalyzer/Core/CheckerContext.cpp clang/lib/StaticAnalyzer/Core/ExprEngine.cpp clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp clang/lib/StaticAnalyzer/Core/ProgramState.cpp clang/lib/StaticAnalyzer/Core/RegionStore.cpp clang/lib/StaticAnalyzer/Core/SValBuilder.cpp clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp clang/lib/StaticAnalyzer/Core/Store.cpp
Index: clang/lib/StaticAnalyzer/Core/Store.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/Store.cpp +++ 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<loc::ConcreteInt>()) + if (Base.isUnknownOrUndef() || isa<loc::ConcreteInt>(Base)) return Base; - if (Base.getAs<loc::GotoLabel>()) + if (isa<loc::GotoLabel>(Base)) return UnknownVal(); const SubRegion *BaseRegion = @@ -488,7 +488,7 @@ SVal BaseIdx = ElemR->getIndex(); - if (!BaseIdx.getAs<nonloc::ConcreteInt>()) + if (!isa<nonloc::ConcreteInt>(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<nonloc::ConcreteInt>()) { + if (!isa<nonloc::ConcreteInt>(Offset)) { if (isa<ElementRegion>(BaseRegion->StripCasts())) return UnknownVal(); Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp +++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp @@ -886,7 +886,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<loc::MemRegionVal>() || rhs.getAs<loc::GotoLabel>()); + assert((isa<loc::MemRegionVal, loc::GotoLabel>(rhs))); if (lhs.isZeroConstant()) { switch (op) { default: Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp +++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp @@ -462,8 +462,7 @@ if (lhs.isUnknown() || rhs.isUnknown()) return UnknownVal(); - if (lhs.getAs<nonloc::LazyCompoundVal>() || - rhs.getAs<nonloc::LazyCompoundVal>()) { + if (isa<nonloc::LazyCompoundVal>(lhs) || isa<nonloc::LazyCompoundVal>(rhs)) { return UnknownVal(); } Index: clang/lib/StaticAnalyzer/Core/RegionStore.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/RegionStore.cpp +++ 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<loc::ConcreteInt>()) + if (isa<loc::ConcreteInt>(Array)) return Array; - if (!Array.getAs<loc::MemRegionVal>()) + if (!isa<loc::MemRegionVal>(Array)) return UnknownVal(); const SubRegion *R = @@ -1378,8 +1378,8 @@ //===----------------------------------------------------------------------===// SVal RegionStoreManager::getBinding(RegionBindingsConstRef B, Loc L, QualType T) { - assert(!L.getAs<UnknownVal>() && "location unknown"); - assert(!L.getAs<UndefinedVal>() && "location undefined"); + assert(!isa<UnknownVal>(L) && "location unknown"); + assert(!isa<UndefinedVal>(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<nonloc::LazyCompoundVal>() || - val.getAs<nonloc::CompoundVal>()) + if (isa<nonloc::LazyCompoundVal, nonloc::CompoundVal>(val)) return val; llvm_unreachable("Unknown default value"); @@ -2414,7 +2413,7 @@ } // Handle lazy compound values. - if (Init.getAs<nonloc::LazyCompoundVal>()) + if (isa<nonloc::LazyCompoundVal>(Init)) return bindAggregate(B, R, Init); if (Init.isUnknown()) @@ -2459,13 +2458,13 @@ const VectorType *VT = T->castAs<VectorType>(); // Use castAs for typedefs. // Handle lazy compound values and symbolic values. - if (V.getAs<nonloc::LazyCompoundVal>() || V.getAs<nonloc::SymbolVal>()) + if (isa<nonloc::LazyCompoundVal, nonloc::SymbolVal>(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<nonloc::CompoundVal>()) { + if (!isa<nonloc::CompoundVal>(V)) { return bindAggregate(B, R, UnknownVal()); } @@ -2551,13 +2550,13 @@ return *NewB; return bindAggregate(B, R, V); } - if (V.getAs<nonloc::SymbolVal>()) + if (isa<nonloc::SymbolVal>(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<nonloc::CompoundVal>()) + if (V.isUnknown() || !isa<nonloc::CompoundVal>(V)) return bindAggregate(B, R, UnknownVal()); // The raw CompoundVal is essentially a symbolic InitListExpr: an (immutable) Index: clang/lib/StaticAnalyzer/Core/ProgramState.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/ProgramState.cpp +++ clang/lib/StaticAnalyzer/Core/ProgramState.cpp @@ -216,7 +216,7 @@ } ProgramStateRef ProgramState::killBinding(Loc LV) const { - assert(!LV.getAs<loc::MemRegionVal>() && "Use invalidateRegion instead."); + assert(!isa<loc::MemRegionVal>(LV) && "Use invalidateRegion instead."); Store OldStore = getStore(); const StoreRef &newStore = Index: clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp +++ 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<Loc>()) + if (!isa<Loc>(V)) return V; // If the types already match, don't do any unnecessary work. Index: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp +++ 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<Loc>() && - Ty->isIntegralOrEnumerationType() && + if (isa<Loc>(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<nonloc::PointerToMember>()) { + if (isa<nonloc::PointerToMember>(V)) { state = state->BindExpr(CastE, LCtx, UnknownVal()); Bldr.generateNode(CastE, Pred, state); continue; Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -312,7 +312,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<NonLoc>()) { + if (!isa<NonLoc>(InitValWithAdjustments)) { if (OutRegionWithAdjustments) *OutRegionWithAdjustments = nullptr; return State; @@ -321,7 +321,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<Loc>() || + assert(!isa<Loc>(InitValWithAdjustments) || Loc::isLocType(Result->getType()) || Result->getType()->isMemberPointerType()); } @@ -2343,7 +2343,7 @@ llvm_unreachable("No block with label."); } - if (V.getAs<loc::ConcreteInt>() || V.getAs<UndefinedVal>()) { + if (isa<UndefinedVal, loc::ConcreteInt>(V)) { // Dispatch to the first target and mark it as a sink. //ExplodedNode* N = builder.generateNode(builder.begin(), state, true); // FIXME: add checker visit. @@ -2894,7 +2894,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<Loc>()) { + if (!isa<Loc>(location)) { const ProgramPoint L = PostStore(StoreE, LC, /*Loc*/nullptr, /*tag*/nullptr); ProgramStateRef state = Pred->getState(); @@ -2964,7 +2964,7 @@ SVal location, const ProgramPointTag *tag, QualType LoadTy) { - assert(!location.getAs<NonLoc>() && "location cannot be a NonLoc."); + assert(!isa<NonLoc>(location) && "location cannot be a NonLoc."); assert(NodeEx); assert(BoundEx); // Evaluate the location (checks for bad dereferences). @@ -3095,7 +3095,7 @@ for (const Expr *O : A->outputs()) { SVal X = state->getSVal(O, Pred->getLocationContext()); - assert(!X.getAs<NonLoc>()); // Should be an Lval, or unknown, undef. + assert(!isa<NonLoc>(X)); // Should be an Lval, or unknown, undef. if (Optional<Loc> LV = X.getAs<Loc>()) state = state->bindLoc(*LV, UnknownVal(), Pred->getLocationContext()); Index: clang/lib/StaticAnalyzer/Core/CheckerContext.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/CheckerContext.cpp +++ clang/lib/StaticAnalyzer/Core/CheckerContext.cpp @@ -127,10 +127,10 @@ if (LHSVal.isUnknownOrUndef()) return false; ProgramStateManager &Mgr = State->getStateManager(); - if (!LHSVal.getAs<NonLoc>()) { + if (!isa<NonLoc>(LHSVal)) { LHSVal = Mgr.getStoreManager().getBinding(State->getStore(), LHSVal.castAs<Loc>()); - if (LHSVal.isUnknownOrUndef() || !LHSVal.getAs<NonLoc>()) + if (LHSVal.isUnknownOrUndef() || !isa<NonLoc>(LHSVal)) return false; } Index: clang/lib/StaticAnalyzer/Core/CallEvent.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/CallEvent.cpp +++ clang/lib/StaticAnalyzer/Core/CallEvent.cpp @@ -680,7 +680,7 @@ return UnknownVal(); SVal ThisVal = getSVal(Base); - assert(ThisVal.isUnknownOrUndef() || ThisVal.getAs<Loc>()); + assert(ThisVal.isUnknownOrUndef() || isa<Loc>(ThisVal)); return ThisVal; } Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -919,7 +919,7 @@ const SVal V) { AnalyzerOptions &Options = N->getState()->getAnalysisManager().options; if (EnableNullFPSuppression && Options.ShouldSuppressNullReturnPaths && - V.getAs<Loc>()) + isa<Loc>(V)) BR.addVisitor<MacroNullReturnSuppressionVisitor>(R->getAs<SubRegion>(), V); } @@ -1035,14 +1035,13 @@ if (RetE->isGLValue()) { if ((LValue = V.getAs<Loc>())) { SVal RValue = State->getRawSVal(*LValue, RetE->getType()); - if (RValue.getAs<DefinedSVal>()) + if (isa<DefinedSVal>(RValue)) V = RValue; } } // Ignore aggregate rvalues. - if (V.getAs<nonloc::LazyCompoundVal>() || - V.getAs<nonloc::CompoundVal>()) + if (isa<nonloc::LazyCompoundVal, nonloc::CompoundVal>(V)) return nullptr; RetE = RetE->IgnoreParenCasts(); @@ -1057,7 +1056,7 @@ bool WouldEventBeMeaningless = false; if (State->isNull(V).isConstrainedTrue()) { - if (V.getAs<Loc>()) { + if (isa<Loc>(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 @@ -1087,10 +1086,7 @@ if (N->getCFG().size() == 3) WouldEventBeMeaningless = true; - if (V.getAs<Loc>()) - Out << "Returning pointer"; - else - Out << "Returning value"; + Out << (isa<Loc>(V) ? "Returning pointer" : "Returning value"); } } @@ -1313,7 +1309,7 @@ llvm_unreachable("Unexpected store kind"); } - if (SI.Value.getAs<loc::ConcreteInt>()) { + if (isa<loc::ConcreteInt>(SI.Value)) { OS << Action << (isObjCPointer(SI.Dest) ? "nil" : "a null pointer value"); } else if (auto CVal = SI.Value.getAs<nonloc::ConcreteInt>()) { @@ -1356,7 +1352,7 @@ OS << "Passing "; - if (SI.Value.getAs<loc::ConcreteInt>()) { + if (isa<loc::ConcreteInt>(SI.Value)) { OS << (isObjCPointer(Param) ? "nil object reference" : "null pointer value"); @@ -1387,7 +1383,7 @@ StoreInfo SI) { const bool HasSuffix = SI.Dest->canPrintPretty(); - if (SI.Value.getAs<loc::ConcreteInt>()) { + if (isa<loc::ConcreteInt>(SI.Value)) { OS << (isObjCPointer(SI.Dest) ? "nil object reference stored" : (HasSuffix ? "Null pointer value stored" : "Storing null pointer value")); @@ -1685,7 +1681,7 @@ SmallString<64> sbuf; llvm::raw_svector_ostream os(sbuf); - if (Constraint.getAs<Loc>()) { + if (isa<Loc>(Constraint)) { os << "Assuming pointer value is "; os << (Assumption ? "non-null" : "null"); } Index: clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp @@ -278,8 +278,7 @@ if (!State) return; - auto ArraySizeNL = ArraySize.getAs<NonLoc>(); - if (!ArraySizeNL) { + if (!isa<NonLoc>(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<DefinedOrUnknownSVal>(), SVB); + ArraySize.castAs<NonLoc>(), SVB); } // Remember our assumptions! Index: clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp @@ -229,7 +229,7 @@ // Now check if oflags has O_CREAT set. const Expr *oflagsEx = CE->getArg(FlagsArgIndex); const SVal V = C.getSVal(oflagsEx); - if (!V.getAs<NonLoc>()) { + if (!isa<NonLoc>(V)) { // The case where 'V' can be a location can only be due to a bad header, // so in this case bail out. return; Index: clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp +++ clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp @@ -141,10 +141,10 @@ SVal V = State->getSVal(FR); assert((isDereferencableType(FR->getDecl()->getType()) || - V.getAs<nonloc::LocAsInteger>()) && + isa<nonloc::LocAsInteger>(V)) && "This method only checks dereferenceable objects!"); - if (V.isUnknown() || V.getAs<loc::ConcreteInt>()) { + if (V.isUnknown() || isa<loc::ConcreteInt>(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<nonloc::LocAsInteger>(); + bool NeedsCastBack = + isVoidPointer(FR->getDecl()->getType()) || isa<nonloc::LocAsInteger>(V); // The region we'd like to acquire. const auto *R = V.getAsRegion()->getAs<TypedValueRegion>(); Index: clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp @@ -330,7 +330,7 @@ SVal V = State->getSVal(FieldVal); - if (isDereferencableType(T) || V.getAs<nonloc::LocAsInteger>()) { + if (isDereferencableType(T) || isa<nonloc::LocAsInteger>(V)) { if (isDereferencableUninit(FR, LocalChain)) ContainsUninitField = true; continue; Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp @@ -254,7 +254,7 @@ return State; DefinedOrUnknownSVal L = V.castAs<DefinedOrUnknownSVal>(); - if (!L.getAs<Loc>()) + if (!isa<Loc>(L)) return State; return State->assume(L, CannotBeNull); Index: clang/lib/StaticAnalyzer/Checkers/STLAlgorithmModeling.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/STLAlgorithmModeling.cpp +++ clang/lib/StaticAnalyzer/Checkers/STLAlgorithmModeling.cpp @@ -131,7 +131,7 @@ nonloc::SymbolVal(NewPos->getOffset()), nonloc::SymbolVal(Pos->getOffset()), SVB.getConditionType()); - assert(GreaterOrEqual.getAs<DefinedSVal>() && + assert(isa<DefinedSVal>(GreaterOrEqual) && "Symbol comparison must be a `DefinedSVal`"); StateFound = StateFound->assume(GreaterOrEqual.castAs<DefinedSVal>(), true); } @@ -153,7 +153,7 @@ nonloc::SymbolVal(NewPos->getOffset()), nonloc::SymbolVal(Pos->getOffset()), SVB.getConditionType()); - assert(Less.getAs<DefinedSVal>() && + assert(isa<DefinedSVal>(Less) && "Symbol comparison must be a `DefinedSVal`"); StateFound = StateFound->assume(Less.castAs<DefinedSVal>(), true); } Index: clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp @@ -413,7 +413,7 @@ AnalysisDeclContext *analCtx = C.getCurrentAnalysisDeclContext(); if (!analCtx->getSelfDecl()) return false; - if (!location.getAs<loc::MemRegionVal>()) + if (!isa<loc::MemRegionVal>(location)) return false; loc::MemRegionVal MRV = location.castAs<loc::MemRegionVal>(); Index: clang/lib/StaticAnalyzer/Checkers/ObjCAtSyncChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/ObjCAtSyncChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/ObjCAtSyncChecker.cpp @@ -41,7 +41,7 @@ SVal V = C.getSVal(Ex); // Uninitialized value used for the mutex? - if (V.getAs<UndefinedVal>()) { + if (isa<UndefinedVal>(V)) { if (ExplodedNode *N = C.generateErrorNode()) { if (!BT_undef) BT_undef.reset(new BuiltinBug(this, "Uninitialized value used as mutex " Index: clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp @@ -136,10 +136,10 @@ if (!DV) continue; - assert(!HasRefTypeParam || DV->getAs<Loc>()); + assert(!HasRefTypeParam || isa<Loc>(DV.getValue())); // Process the case when the argument is not a location. - if (ExpectedToBeNonNull && !DV->getAs<Loc>()) { + if (ExpectedToBeNonNull && !isa<Loc>(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<Loc>()) + if (!isa<Loc>(V)) continue; // Retrieve the corresponding expression. Index: clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp @@ -214,7 +214,7 @@ CheckerContext &C) const { if (!isLoad) return; - if (loc.isUndef() || !loc.getAs<Loc>()) + if (loc.isUndef() || !isa<Loc>(loc)) return; ASTContext &Ctx = C.getASTContext(); Index: clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp @@ -48,8 +48,8 @@ CheckerContext &C) const { if (matchesAny(Call, MmapFn, MprotectFn)) { SVal ProtVal = Call.getArgSVal(2); - Optional<nonloc::ConcreteInt> ProtLoc = ProtVal.getAs<nonloc::ConcreteInt>(); - int64_t Prot = ProtLoc->getValue().getSExtValue(); + auto ProtLoc = ProtVal.castAs<nonloc::ConcreteInt>(); + int64_t Prot = ProtLoc.getValue().getSExtValue(); if (ProtExecOv != ProtExec) ProtExec = ProtExecOv; if (ProtReadOv != ProtRead) Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -1187,7 +1187,7 @@ const Expr *FlagsEx = Call.getArgExpr(Call.getNumArgs() - 1); const SVal V = C.getSVal(FlagsEx); - if (!V.getAs<NonLoc>()) { + if (!isa<NonLoc>(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; @@ -1912,12 +1912,12 @@ return nullptr; SVal ArgVal = C.getSVal(ArgExpr); - if (!ArgVal.getAs<DefinedOrUnknownSVal>()) + if (!isa<DefinedOrUnknownSVal>(ArgVal)) return nullptr; DefinedOrUnknownSVal location = ArgVal.castAs<DefinedOrUnknownSVal>(); // Check for null dereferences. - if (!location.getAs<Loc>()) + if (!isa<Loc>(location)) return nullptr; // The explicit NULL case, no operation is performed. @@ -2587,7 +2587,7 @@ const Expr *arg0Expr = CE->getArg(0); SVal Arg0Val = C.getSVal(arg0Expr); - if (!Arg0Val.getAs<DefinedOrUnknownSVal>()) + if (!isa<DefinedOrUnknownSVal>(Arg0Val)) return nullptr; DefinedOrUnknownSVal arg0Val = Arg0Val.castAs<DefinedOrUnknownSVal>(); @@ -2603,7 +2603,7 @@ SVal TotalSize = C.getSVal(Arg1); if (SuffixWithN) TotalSize = evalMulForBufferSize(C, Arg1, CE->getArg(2)); - if (!TotalSize.getAs<DefinedOrUnknownSVal>()) + if (!isa<DefinedOrUnknownSVal>(TotalSize)) return nullptr; // Compare the size argument to 0. @@ -2913,7 +2913,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<Loc>()) { + if (isa<Loc>(ArgSVal)) { SymbolRef Sym = ArgSVal.getAsSymbol(); if (!Sym) continue; Index: clang/lib/StaticAnalyzer/Checkers/MPI-Checker/MPIChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/MPI-Checker/MPIChecker.cpp +++ 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<nonloc::ConcreteInt>()->getValue(); + ElementCount.castAs<nonloc::ConcreteInt>().getValue(); for (size_t i = 0; i < ArrSize; ++i) { const NonLoc Idx = Ctx.getSValBuilder().makeArrayIndex(i); Index: clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp +++ clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp @@ -631,7 +631,7 @@ const Expr *Iterator, OverloadedOperatorKind OK, SVal Offset) const { - if (!Offset.getAs<DefinedSVal>()) + if (!isa<DefinedSVal>(Offset)) return; QualType PtrType = Iterator->getType(); @@ -801,8 +801,8 @@ SVB.evalBinOp(State, BO_EQ, nonloc::SymbolVal(Sym1), nonloc::SymbolVal(Sym2), SVB.getConditionType()); - assert(comparison.getAs<DefinedSVal>() && - "Symbol comparison must be a `DefinedSVal`"); + assert(isa<DefinedSVal>(comparison) && + "Symbol comparison must be a `DefinedSVal`"); auto NewState = State->assume(comparison.castAs<DefinedSVal>(), Equal); if (!NewState) Index: clang/lib/StaticAnalyzer/Checkers/Iterator.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/Iterator.cpp +++ clang/lib/StaticAnalyzer/Checkers/Iterator.cpp @@ -308,8 +308,8 @@ const auto comparison = SVB.evalBinOp(State, Opc, NL1, NL2, SVB.getConditionType()); - assert(comparison.getAs<DefinedSVal>() && - "Symbol comparison must be a `DefinedSVal`"); + assert(isa<DefinedSVal>(comparison) && + "Symbol comparison must be a `DefinedSVal`"); return !State->assume(comparison.castAs<DefinedSVal>(), false); } Index: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp @@ -866,7 +866,7 @@ return; const auto WouldEscape = [](SVal V, QualType Ty) -> bool { - if (!V.getAs<Loc>()) + if (!isa<Loc>(V)) return false; const bool IsNonConstRef = Ty->isReferenceType() && !Ty.isConstQualified(); Index: clang/lib/StaticAnalyzer/Checkers/GTestChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/GTestChecker.cpp +++ 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<Loc>()) + if (!isa<Loc>(BooleanArgVal)) return; BooleanArgVal = C.getState()->getSVal(BooleanArgVal.castAs<Loc>()); } @@ -270,20 +270,17 @@ ProgramStateRef GTestChecker::assumeValuesEqual(SVal Val1, SVal Val2, ProgramStateRef State, CheckerContext &C) { - if (!Val1.getAs<DefinedOrUnknownSVal>() || - !Val2.getAs<DefinedOrUnknownSVal>()) + auto DVal1 = Val1.getAs<DefinedOrUnknownSVal>(); + auto DVal2 = Val2.getAs<DefinedOrUnknownSVal>(); + if (!DVal1.hasValue() || !DVal2.hasValue()) return State; auto ValuesEqual = - C.getSValBuilder().evalEQ(State, Val1.castAs<DefinedOrUnknownSVal>(), - Val2.castAs<DefinedOrUnknownSVal>()); - - if (!ValuesEqual.getAs<DefinedSVal>()) + C.getSValBuilder().evalEQ(State, *DVal1, *DVal2).getAs<DefinedSVal>(); + if (!ValuesEqual.hasValue()) return State; - State = C.getConstraintManager().assume( - State, ValuesEqual.castAs<DefinedSVal>(), true); - + State = C.getConstraintManager().assume(State, *ValuesEqual, true); return State; } Index: clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp @@ -248,7 +248,7 @@ DefinedOrUnknownSVal location = l.castAs<DefinedOrUnknownSVal>(); // Check for null dereferences. - if (!location.getAs<Loc>()) + if (!isa<Loc>(location)) return; ProgramStateRef state = C.getState(); Index: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp @@ -696,7 +696,7 @@ NonLoc maxVal = svalBuilder.makeIntVal(maxValInt); SVal maxMinusRight; - if (right.getAs<nonloc::ConcreteInt>()) { + if (isa<nonloc::ConcreteInt>(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<NonLoc>()) + if (!isa<NonLoc>(freeSpace)) return; freeSpace = svalBuilder.evalBinOp(state, BO_Sub, freeSpace, Index: clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp +++ clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp @@ -758,7 +758,7 @@ continue; // Ignore pointer constants. - if (msg.getArgSVal(I).getAs<loc::ConcreteInt>()) + if (isa<loc::ConcreteInt>(msg.getArgSVal(I))) continue; // Ignore pointer types annotated with 'NSObject' attribute. Index: clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp +++ clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp @@ -144,10 +144,9 @@ SVal extentBegin = computeExtentBegin(svalBuilder, rawOffset.getRegion()); if (Optional<NonLoc> NV = extentBegin.getAs<NonLoc>()) { - if (NV->getAs<nonloc::ConcreteInt>()) { + if (auto ConcreteNV = NV->getAs<nonloc::ConcreteInt>()) { std::pair<NonLoc, nonloc::ConcreteInt> simplifiedOffsets = - getSimplifiedOffsets(rawOffset.getByteOffset(), - NV->castAs<nonloc::ConcreteInt>(), + 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<NonLoc>()) + if (!isa<NonLoc>(Size)) break; - if (Size.getAs<nonloc::ConcreteInt>()) { + if (auto ConcreteSize = Size.getAs<nonloc::ConcreteInt>()) { std::pair<NonLoc, nonloc::ConcreteInt> simplifiedOffsets = - getSimplifiedOffsets(rawOffset.getByteOffset(), - Size.castAs<nonloc::ConcreteInt>(), 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<UndefinedVal>() ? 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<ElementRegion>(region); SVal index = elemReg->getIndex(); - if (!index.getAs<NonLoc>()) + if (!isa<NonLoc>(index)) return RegionRawOffsetV2(); QualType elemType = elemReg->getElementType(); // If the element is an incomplete type, go no further. Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h =================================================================== --- clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h +++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h @@ -727,7 +727,7 @@ if (Val.isUnknown()) return this; - assert(Val.getAs<NonLoc>() && "Only NonLocs are supported!"); + assert(isa<NonLoc>(Val) && "Only NonLocs are supported!"); return getStateManager().ConstraintMgr->assumeInclusiveRange( this, Val.castAs<NonLoc>(), From, To, Assumption); @@ -740,7 +740,7 @@ if (Val.isUnknown()) return std::make_pair(this, this); - assert(Val.getAs<NonLoc>() && "Only NonLocs are supported!"); + assert(isa<NonLoc>(Val) && "Only NonLocs are supported!"); return getStateManager().ConstraintMgr->assumeInclusiveRangeDual( this, Val.castAs<NonLoc>(), From, To); Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h =================================================================== --- clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h +++ 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<nonloc::ConcreteInt>() || + assert((!isa<nonloc::ConcreteInt>(Idx) || Idx.castAs<nonloc::ConcreteInt>().getValue().isSigned()) && "The index must be signed"); assert(!elementType.isNull() && !elementType->isVoidType() && Index: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h =================================================================== --- clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h +++ 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<Loc>()) {} + IsZeroCheck(!Assumption && isa<Loc>(Constraint)) {} void Profile(llvm::FoldingSetNodeID &ID) const override;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits