From: David Blaikie Date: Thu, 21 Feb 2013 22:23:56 +0000 (+0000) Subject: Replace ProgramPoint llvm::cast support to be well-defined. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=87396b9b08551ff86a788ff41da17b71e4dd4820;p=platform%2Fupstream%2Fllvm.git Replace ProgramPoint llvm::cast support to be well-defined. See r175462 for another example/more details. llvm-svn: 175812 --- diff --git a/clang/include/clang/Analysis/ProgramPoint.h b/clang/include/clang/Analysis/ProgramPoint.h index 322f0cb..27d4ff1 100644 --- a/clang/include/clang/Analysis/ProgramPoint.h +++ b/clang/include/clang/Analysis/ProgramPoint.h @@ -19,6 +19,7 @@ #include "clang/Analysis/CFG.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/FoldingSet.h" +#include "llvm/ADT/Optional.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Casting.h" @@ -71,9 +72,8 @@ private: llvm::PointerIntPair Tag; - ProgramPoint(); - protected: + ProgramPoint() {} ProgramPoint(const void *P, Kind k, const LocationContext *l, @@ -110,6 +110,29 @@ public: getLocationContext(), tag); } + /// \brief Convert to the specified TypeLoc type, asserting that this TypeLoc + /// is of the desired type. + template + T castAs() const { + assert(T::isKind(*this)); + T t; + ProgramPoint& PP = t; + PP = *this; + return t; + } + + /// \brief Convert to the specified TypeLoc type, returning a null TypeLoc if + /// this TypeLoc is not of the desired type. + template + Optional getAs() const { + if (!T::isKind(*this)) + return None; + T t; + ProgramPoint& PP = t; + PP = *this; + return t; + } + Kind getKind() const { unsigned x = Tag.getInt(); x <<= 2; @@ -184,8 +207,11 @@ public: return B->empty() ? CFGElement() : B->front(); } - static bool classof(const ProgramPoint* Location) { - return Location->getKind() == BlockEntranceKind; +private: + friend class ProgramPoint; + BlockEntrance() {} + static bool isKind(const ProgramPoint &Location) { + return Location.getKind() == BlockEntranceKind; } }; @@ -202,8 +228,11 @@ public: return getBlock()->getTerminator(); } - static bool classof(const ProgramPoint* Location) { - return Location->getKind() == BlockExitKind; +private: + friend class ProgramPoint; + BlockExit() {} + static bool isKind(const ProgramPoint &Location) { + return Location.getKind() == BlockExitKind; } }; @@ -220,8 +249,12 @@ public: template const T* getStmtAs() const { return dyn_cast(getStmt()); } - static bool classof(const ProgramPoint* Location) { - unsigned k = Location->getKind(); +protected: + StmtPoint() {} +private: + friend class ProgramPoint; + static bool isKind(const ProgramPoint &Location) { + unsigned k = Location.getKind(); return k >= PreStmtKind && k <= MaxPostStmtKind; } }; @@ -235,13 +268,17 @@ public: const Stmt *getSubStmt() const { return (const Stmt*) getData2(); } - static bool classof(const ProgramPoint* Location) { - return Location->getKind() == PreStmtKind; +private: + friend class ProgramPoint; + PreStmt() {} + static bool isKind(const ProgramPoint &Location) { + return Location.getKind() == PreStmtKind; } }; class PostStmt : public StmtPoint { protected: + PostStmt() {} PostStmt(const Stmt *S, const void *data, Kind k, const LocationContext *L, const ProgramPointTag *tag = 0) : StmtPoint(S, data, k, L, tag) {} @@ -255,8 +292,10 @@ public: const ProgramPointTag *tag = 0) : StmtPoint(S, NULL, PostStmtKind, L, tag) {} - static bool classof(const ProgramPoint* Location) { - unsigned k = Location->getKind(); +private: + friend class ProgramPoint; + static bool isKind(const ProgramPoint &Location) { + unsigned k = Location.getKind(); return k >= MinPostStmtKind && k <= MaxPostStmtKind; } }; @@ -268,19 +307,25 @@ public: const ProgramPointTag *tag = 0) : PostStmt(S, PostConditionKind, L, tag) {} - static bool classof(const ProgramPoint* Location) { - return Location->getKind() == PostConditionKind; +private: + friend class ProgramPoint; + PostCondition() {} + static bool isKind(const ProgramPoint &Location) { + return Location.getKind() == PostConditionKind; } }; class LocationCheck : public StmtPoint { protected: + LocationCheck() {} LocationCheck(const Stmt *S, const LocationContext *L, ProgramPoint::Kind K, const ProgramPointTag *tag) : StmtPoint(S, NULL, K, L, tag) {} - static bool classof(const ProgramPoint *location) { - unsigned k = location->getKind(); +private: + friend class ProgramPoint; + static bool isKind(const ProgramPoint &location) { + unsigned k = location.getKind(); return k == PreLoadKind || k == PreStoreKind; } }; @@ -291,8 +336,11 @@ public: const ProgramPointTag *tag = 0) : LocationCheck(S, L, PreLoadKind, tag) {} - static bool classof(const ProgramPoint *location) { - return location->getKind() == PreLoadKind; +private: + friend class ProgramPoint; + PreLoad() {} + static bool isKind(const ProgramPoint &location) { + return location.getKind() == PreLoadKind; } }; @@ -302,8 +350,11 @@ public: const ProgramPointTag *tag = 0) : LocationCheck(S, L, PreStoreKind, tag) {} - static bool classof(const ProgramPoint *location) { - return location->getKind() == PreStoreKind; +private: + friend class ProgramPoint; + PreStore() {} + static bool isKind(const ProgramPoint &location) { + return location.getKind() == PreStoreKind; } }; @@ -313,8 +364,11 @@ public: const ProgramPointTag *tag = 0) : PostStmt(S, PostLoadKind, L, tag) {} - static bool classof(const ProgramPoint* Location) { - return Location->getKind() == PostLoadKind; +private: + friend class ProgramPoint; + PostLoad() {} + static bool isKind(const ProgramPoint &Location) { + return Location.getKind() == PostLoadKind; } }; @@ -331,16 +385,18 @@ public: setData2(Loc); } - static bool classof(const ProgramPoint* Location) { - return Location->getKind() == PostStoreKind; - } - /// \brief Returns the information about the location used in the store, /// how it was uttered in the code. const void *getLocationValue() const { return getData2(); } +private: + friend class ProgramPoint; + PostStore() {} + static bool isKind(const ProgramPoint &Location) { + return Location.getKind() == PostStoreKind; + } }; class PostLValue : public PostStmt { @@ -349,8 +405,11 @@ public: const ProgramPointTag *tag = 0) : PostStmt(S, PostLValueKind, L, tag) {} - static bool classof(const ProgramPoint* Location) { - return Location->getKind() == PostLValueKind; +private: + friend class ProgramPoint; + PostLValue() {} + static bool isKind(const ProgramPoint &Location) { + return Location.getKind() == PostLValueKind; } }; @@ -362,8 +421,11 @@ public: const ProgramPointTag *tag = 0) : StmtPoint(S, 0, PreStmtPurgeDeadSymbolsKind, L, tag) { } - static bool classof(const ProgramPoint* Location) { - return Location->getKind() == PreStmtPurgeDeadSymbolsKind; +private: + friend class ProgramPoint; + PreStmtPurgeDeadSymbols() {} + static bool isKind(const ProgramPoint &Location) { + return Location.getKind() == PreStmtPurgeDeadSymbolsKind; } }; @@ -375,8 +437,11 @@ public: const ProgramPointTag *tag = 0) : StmtPoint(S, 0, PostStmtPurgeDeadSymbolsKind, L, tag) { } - static bool classof(const ProgramPoint* Location) { - return Location->getKind() == PostStmtPurgeDeadSymbolsKind; +private: + friend class ProgramPoint; + PostStmtPurgeDeadSymbols() {} + static bool isKind(const ProgramPoint &Location) { + return Location.getKind() == PostStmtPurgeDeadSymbolsKind; } }; @@ -396,8 +461,11 @@ public: return static_cast(getData2()); } - static bool classof(const ProgramPoint* Location) { - return Location->getKind() == BlockEdgeKind; +private: + friend class ProgramPoint; + BlockEdge() {} + static bool isKind(const ProgramPoint &Location) { + return Location.getKind() == BlockEdgeKind; } }; @@ -407,8 +475,11 @@ public: const LocationContext *L) : ProgramPoint(I, PostInitializerKind, L) {} - static bool classof(const ProgramPoint *Location) { - return Location->getKind() == PostInitializerKind; +private: + friend class ProgramPoint; + PostInitializer() {} + static bool isKind(const ProgramPoint &Location) { + return Location.getKind() == PostInitializerKind; } }; @@ -426,9 +497,13 @@ public: return SourceLocation::getFromPtrEncoding(getData1()); } - static bool classof(const ProgramPoint *Location) { - return Location->getKind() >= MinImplicitCallKind && - Location->getKind() <= MaxImplicitCallKind; +protected: + ImplicitCallPoint() {} +private: + friend class ProgramPoint; + static bool isKind(const ProgramPoint &Location) { + return Location.getKind() >= MinImplicitCallKind && + Location.getKind() <= MaxImplicitCallKind; } }; @@ -441,8 +516,11 @@ public: const LocationContext *L, const ProgramPointTag *Tag = 0) : ImplicitCallPoint(D, Loc, PreImplicitCallKind, L, Tag) {} - static bool classof(const ProgramPoint *Location) { - return Location->getKind() == PreImplicitCallKind; +private: + friend class ProgramPoint; + PreImplicitCall() {} + static bool isKind(const ProgramPoint &Location) { + return Location.getKind() == PreImplicitCallKind; } }; @@ -455,8 +533,11 @@ public: const LocationContext *L, const ProgramPointTag *Tag = 0) : ImplicitCallPoint(D, Loc, PostImplicitCallKind, L, Tag) {} - static bool classof(const ProgramPoint *Location) { - return Location->getKind() == PostImplicitCallKind; +private: + friend class ProgramPoint; + PostImplicitCall() {} + static bool isKind(const ProgramPoint &Location) { + return Location.getKind() == PostImplicitCallKind; } }; @@ -476,8 +557,11 @@ public: return static_cast(getData2()); } - static bool classof(const ProgramPoint *Location) { - return Location->getKind() == CallEnterKind; +private: + friend class ProgramPoint; + CallEnter() {} + static bool isKind(const ProgramPoint &Location) { + return Location.getKind() == CallEnterKind; } }; @@ -496,8 +580,11 @@ public: CallExitBegin(const StackFrameContext *L) : ProgramPoint(0, CallExitBeginKind, L, 0) {} - static bool classof(const ProgramPoint *Location) { - return Location->getKind() == CallExitBeginKind; +private: + friend class ProgramPoint; + CallExitBegin() {} + static bool isKind(const ProgramPoint &Location) { + return Location.getKind() == CallExitBeginKind; } }; @@ -514,8 +601,11 @@ public: return static_cast(getData1()); } - static bool classof(const ProgramPoint *Location) { - return Location->getKind() == CallExitEndKind; +private: + friend class ProgramPoint; + CallExitEnd() {} + static bool isKind(const ProgramPoint &Location) { + return Location.getKind() == CallExitEndKind; } }; @@ -529,8 +619,11 @@ public: const void *getData() const { return getData1(); } - static bool classof(const ProgramPoint* Location) { - return Location->getKind() == EpsilonKind; +private: + friend class ProgramPoint; + EpsilonPoint() {} + static bool isKind(const ProgramPoint &Location) { + return Location.getKind() == EpsilonKind; } }; @@ -544,7 +637,7 @@ public: virtual StringRef getTagDescription() const = 0; protected: - /// Used to implement 'classof' in subclasses. + /// Used to implement 'isKind' in subclasses. const void *getTagKind() { return TagKind; } private: diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h index ce495c9..cda1366 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h @@ -185,7 +185,7 @@ public: /// example, for finding variables that the given symbol was assigned to. static const MemRegion *getLocationRegionIfPostStore(const ExplodedNode *N) { ProgramPoint L = N->getLocation(); - if (const PostStore *PSL = dyn_cast(&L)) + if (Optional PSL = L.getAs()) return reinterpret_cast(PSL->getLocationValue()); return 0; } diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h index 519924d..82ac3d9 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h @@ -155,15 +155,10 @@ public: const ProgramStateRef &getState() const { return State; } template - const T* getLocationAs() const LLVM_LVALUE_FUNCTION { - return dyn_cast(&Location); + Optional getLocationAs() const LLVM_LVALUE_FUNCTION { + return Location.getAs(); } -#if LLVM_HAS_RVALUE_REFERENCE_THIS - template - void getLocationAs() && LLVM_DELETED_FUNCTION; -#endif - static void Profile(llvm::FoldingSetNodeID &ID, const ProgramPoint &Loc, const ProgramStateRef &state, diff --git a/clang/lib/StaticAnalyzer/Checkers/AnalyzerStatsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/AnalyzerStatsChecker.cpp index 0a12854..217d467 100644 --- a/clang/lib/StaticAnalyzer/Checkers/AnalyzerStatsChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/AnalyzerStatsChecker.cpp @@ -60,7 +60,7 @@ void AnalyzerStatsChecker::checkEndAnalysis(ExplodedGraph &G, if (D != P.getLocationContext()->getDecl()) continue; - if (const BlockEntrance *BE = dyn_cast(&P)) { + if (Optional BE = P.getAs()) { const CFGBlock *CB = BE->getBlock(); reachable.insert(CB); } diff --git a/clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp index 051d60a..312bc74 100644 --- a/clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp @@ -44,7 +44,7 @@ void ArrayBoundChecker::checkLocation(SVal l, bool isLoad, const Stmt* LoadS, return; // Get the index of the accessed element. - DefinedOrUnknownSVal Idx = cast(ER->getIndex()); + DefinedOrUnknownSVal Idx = ER->getIndex().castAs(); // Zero index is always in bound, this also passes ElementRegions created for // pointer casts. diff --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp index d0c4322..cc55e9f 100644 --- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp @@ -281,7 +281,7 @@ ProgramStateRef CStringChecker::CheckLocation(CheckerContext &C, DefinedOrUnknownSVal Size = Extent.castAs(); // Get the index of the accessed element. - DefinedOrUnknownSVal Idx = cast(ER->getIndex()); + DefinedOrUnknownSVal Idx = ER->getIndex().castAs(); ProgramStateRef StInBound = state->assumeInBound(Idx, Size, true); ProgramStateRef StOutBound = state->assumeInBound(Idx, Size, false); diff --git a/clang/lib/StaticAnalyzer/Checkers/IdempotentOperationChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/IdempotentOperationChecker.cpp index 54c32f8..579ba9c 100644 --- a/clang/lib/StaticAnalyzer/Checkers/IdempotentOperationChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/IdempotentOperationChecker.cpp @@ -332,9 +332,9 @@ void IdempotentOperationChecker::checkPostStmt(const BinaryOperator *B, // Add the ExplodedNode we just visited BinaryOperatorData &Data = hash[B]; - const Stmt *predStmt - = cast(C.getPredecessor()->getLocation()).getStmt(); - + const Stmt *predStmt = + C.getPredecessor()->getLocation().castAs().getStmt(); + // Ignore implicit calls to setters. if (!isa(predStmt)) return; @@ -582,16 +582,13 @@ IdempotentOperationChecker::pathWasCompletelyAnalyzed(AnalysisDeclContext *AC, virtual bool visit(const WorkListUnit &U) { ProgramPoint P = U.getNode()->getLocation(); const CFGBlock *B = 0; - if (StmtPoint *SP = dyn_cast(&P)) { + if (Optional SP = P.getAs()) { B = CBM->getBlock(SP->getStmt()); - } - else if (BlockEdge *BE = dyn_cast(&P)) { + } else if (Optional BE = P.getAs()) { B = BE->getDst(); - } - else if (BlockEntrance *BEnt = dyn_cast(&P)) { + } else if (Optional BEnt = P.getAs()) { B = BEnt->getBlock(); - } - else if (BlockExit *BExit = dyn_cast(&P)) { + } else if (Optional BExit = P.getAs()) { B = BExit->getBlock(); } if (!B) diff --git a/clang/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp index 84cad82..2cd4afe 100644 --- a/clang/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp @@ -526,9 +526,9 @@ BugReport *MacOSKeychainAPIChecker:: const ExplodedNode *AllocNode = getAllocationNode(N, AP.first, C); const Stmt *AllocStmt = 0; ProgramPoint P = AllocNode->getLocation(); - if (CallExitEnd *Exit = dyn_cast(&P)) + if (Optional Exit = P.getAs()) AllocStmt = Exit->getCalleeContext()->getCallSite(); - else if (clang::PostStmt *PS = dyn_cast(&P)) + else if (Optional PS = P.getAs()) AllocStmt = PS->getStmt(); if (AllocStmt) @@ -602,8 +602,8 @@ PathDiagnosticPiece *MacOSKeychainAPIChecker::SecKeychainBugVisitor::VisitNode( // (!ASPrev && AS) ~ We started tracking symbol in node N, it must be the // allocation site. - const CallExpr *CE = cast(cast(N->getLocation()) - .getStmt()); + const CallExpr *CE = + cast(N->getLocation().castAs().getStmt()); const FunctionDecl *funDecl = CE->getDirectCallee(); assert(funDecl && "We do not support indirect function calls as of now."); StringRef funName = funDecl->getName(); diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp index 38722a2..f412c04 100644 --- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -1117,9 +1117,9 @@ void MallocChecker::reportLeak(SymbolRef Sym, ExplodedNode *N, ProgramPoint P = AllocNode->getLocation(); const Stmt *AllocationStmt = 0; - if (CallExitEnd *Exit = dyn_cast(&P)) + if (Optional Exit = P.getAs()) AllocationStmt = Exit->getCalleeContext()->getCallSite(); - else if (StmtPoint *SP = dyn_cast(&P)) + else if (Optional SP = P.getAs()) AllocationStmt = SP->getStmt(); if (AllocationStmt) LocUsedForUniqueing = PathDiagnosticLocation::createBegin(AllocationStmt, @@ -1559,11 +1559,11 @@ MallocChecker::MallocBugVisitor::VisitNode(const ExplodedNode *N, // Retrieve the associated statement. ProgramPoint ProgLoc = N->getLocation(); - if (StmtPoint *SP = dyn_cast(&ProgLoc)) { + if (Optional SP = ProgLoc.getAs()) { S = SP->getStmt(); - } else if (CallExitEnd *Exit = dyn_cast(&ProgLoc)) { + } else if (Optional Exit = ProgLoc.getAs()) { S = Exit->getCalleeContext()->getCallSite(); - } else if (BlockEdge *Edge = dyn_cast(&ProgLoc)) { + } else if (Optional Edge = ProgLoc.getAs()) { // If an assumption was made on a branch, it should be caught // here by looking at the state transition. S = Edge->getSrc()->getTerminator(); diff --git a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp index 69191de..65bd033 100644 --- a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp @@ -1866,7 +1866,7 @@ PathDiagnosticPiece *CFRefReportVisitor::VisitNode(const ExplodedNode *N, BugReport &BR) { // FIXME: We will eventually need to handle non-statement-based events // (__attribute__((cleanup))). - if (!isa(N->getLocation())) + if (!N->getLocation().getAs()) return NULL; // Check if the type state has changed. @@ -1888,7 +1888,7 @@ PathDiagnosticPiece *CFRefReportVisitor::VisitNode(const ExplodedNode *N, // This is the allocation site since the previous node had no bindings // for this symbol. if (!PrevT) { - const Stmt *S = cast(N->getLocation()).getStmt(); + const Stmt *S = N->getLocation().castAs().getStmt(); if (isa(S)) { os << "NSArray literal is an object with a +0 retain count"; @@ -1978,7 +1978,7 @@ PathDiagnosticPiece *CFRefReportVisitor::VisitNode(const ExplodedNode *N, if (const RetainSummary *Summ = SummaryLog.lookup(OrigNode)) { // We only have summaries attached to nodes after evaluating CallExpr and // ObjCMessageExprs. - const Stmt *S = cast(N->getLocation()).getStmt(); + const Stmt *S = N->getLocation().castAs().getStmt(); if (const CallExpr *CE = dyn_cast(S)) { // Iterate through the parameter expressions and see if the symbol @@ -2027,7 +2027,7 @@ PathDiagnosticPiece *CFRefReportVisitor::VisitNode(const ExplodedNode *N, // Specially handle CFMakeCollectable and friends. if (contains(AEffects, MakeCollectable)) { // Get the name of the function. - const Stmt *S = cast(N->getLocation()).getStmt(); + const Stmt *S = N->getLocation().castAs().getStmt(); SVal X = CurrSt->getSValAsScalarOrLoc(cast(S)->getCallee(), LCtx); const FunctionDecl *FD = X.getAsFunctionDecl(); @@ -2135,7 +2135,7 @@ PathDiagnosticPiece *CFRefReportVisitor::VisitNode(const ExplodedNode *N, if (os.str().empty()) return 0; // We have nothing to say! - const Stmt *S = cast(N->getLocation()).getStmt(); + const Stmt *S = N->getLocation().castAs().getStmt(); PathDiagnosticLocation Pos(S, BRC.getSourceManager(), N->getLocationContext()); PathDiagnosticPiece *P = new PathDiagnosticEventPiece(Pos, os.str()); @@ -2312,10 +2312,10 @@ CFRefLeakReport::CFRefLeakReport(CFRefBug &D, const LangOptions &LOpts, // implicit call. (Currently there are no such allocations in Cocoa, though.) const Stmt *AllocStmt; ProgramPoint P = AllocNode->getLocation(); - if (CallExitEnd *Exit = dyn_cast(&P)) + if (Optional Exit = P.getAs()) AllocStmt = Exit->getCalleeContext()->getCallSite(); else - AllocStmt = cast(P).getStmt(); + AllocStmt = P.castAs().getStmt(); assert(AllocStmt && "All allocations must come from explicit calls"); Location = PathDiagnosticLocation::createBegin(AllocStmt, SMgr, n->getLocationContext()); diff --git a/clang/lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp index 59df516..fe253b7 100644 --- a/clang/lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp @@ -46,7 +46,7 @@ void ReturnPointerRangeChecker::checkPreStmt(const ReturnStmt *RS, if (!ER) return; - DefinedOrUnknownSVal Idx = cast(ER->getIndex()); + DefinedOrUnknownSVal Idx = ER->getIndex().castAs(); // Zero index is always in bound, this also passes ElementRegions created for // pointer casts. if (Idx.isZeroConstant()) diff --git a/clang/lib/StaticAnalyzer/Checkers/UndefBranchChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/UndefBranchChecker.cpp index 54e4016..8235e68 100644 --- a/clang/lib/StaticAnalyzer/Checkers/UndefBranchChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/UndefBranchChecker.cpp @@ -90,7 +90,7 @@ void UndefBranchChecker::checkBranchCondition(const Stmt *Condition, ProgramPoint P = PrevN->getLocation(); ProgramStateRef St = N->getState(); - if (PostStmt *PS = dyn_cast(&P)) + if (Optional PS = P.getAs()) if (PS->getStmt() == Ex) St = PrevN->getState(); diff --git a/clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp index c939d05..3b4aa23 100644 --- a/clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp @@ -76,7 +76,7 @@ void UnreachableCodeChecker::checkEndAnalysis(ExplodedGraph &G, if (!PM) PM = &LC->getParentMap(); - if (const BlockEntrance *BE = dyn_cast(&P)) { + if (Optional BE = P.getAs()) { const CFGBlock *CB = BE->getBlock(); reachable.insert(CB->getBlockID()); } diff --git a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp index d43d525..8556089 100644 --- a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp +++ b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp @@ -44,13 +44,13 @@ void BugReporterContext::anchor() {} //===----------------------------------------------------------------------===// static inline const Stmt *GetStmt(const ProgramPoint &P) { - if (const StmtPoint* SP = dyn_cast(&P)) + if (Optional SP = P.getAs()) return SP->getStmt(); - else if (const BlockEdge *BE = dyn_cast(&P)) + if (Optional BE = P.getAs()) return BE->getSrc()->getTerminator(); - else if (const CallEnter *CE = dyn_cast(&P)) + if (Optional CE = P.getAs()) return CE->getCallExpr(); - else if (const CallExitEnd *CEE = dyn_cast(&P)) + if (Optional CEE = P.getAs()) return CEE->getCalleeContext()->getCallSite(); return 0; @@ -579,7 +579,7 @@ static bool GenerateMinimalPathDiagnostic(PathDiagnostic& PD, ProgramPoint P = N->getLocation(); do { - if (const CallExitEnd *CE = dyn_cast(&P)) { + if (Optional CE = P.getAs()) { PathDiagnosticCallPiece *C = PathDiagnosticCallPiece::construct(N, *CE, SMgr); GRBugReporter& BR = PDB.getBugReporter(); @@ -590,7 +590,7 @@ static bool GenerateMinimalPathDiagnostic(PathDiagnostic& PD, break; } - if (const CallEnter *CE = dyn_cast(&P)) { + if (Optional CE = P.getAs()) { // Flush all locations, and pop the active path. bool VisitedEntireCall = PD.isWithinCall(); PD.popActivePath(); @@ -618,7 +618,7 @@ static bool GenerateMinimalPathDiagnostic(PathDiagnostic& PD, break; } - if (const BlockEdge *BE = dyn_cast(&P)) { + if (Optional BE = P.getAs()) { const CFGBlock *Src = BE->getSrc(); const CFGBlock *Dst = BE->getDst(); const Stmt *T = Src->getTerminator(); @@ -1334,14 +1334,14 @@ static bool GenerateExtensivePathDiagnostic(PathDiagnostic& PD, ProgramPoint P = N->getLocation(); do { - if (const PostStmt *PS = dyn_cast(&P)) { + if (Optional PS = P.getAs()) { if (const Expr *Ex = PS->getStmtAs()) reversePropagateIntererstingSymbols(*PDB.getBugReport(), IE, N->getState().getPtr(), Ex, N->getLocationContext()); } - if (const CallExitEnd *CE = dyn_cast(&P)) { + if (Optional CE = P.getAs()) { const Stmt *S = CE->getCalleeContext()->getCallSite(); if (const Expr *Ex = dyn_cast_or_null(S)) { reversePropagateIntererstingSymbols(*PDB.getBugReport(), IE, @@ -1365,7 +1365,7 @@ static bool GenerateExtensivePathDiagnostic(PathDiagnostic& PD, // Pop the call hierarchy if we are done walking the contents // of a function call. - if (const CallEnter *CE = dyn_cast(&P)) { + if (Optional CE = P.getAs()) { // Add an edge to the start of the function. const Decl *D = CE->getCalleeContext()->getDecl(); PathDiagnosticLocation pos = @@ -1410,7 +1410,7 @@ static bool GenerateExtensivePathDiagnostic(PathDiagnostic& PD, PDB.LC = N->getLocationContext(); // Block edges. - if (const BlockEdge *BE = dyn_cast(&P)) { + if (Optional BE = P.getAs()) { // Does this represent entering a call? If so, look at propagating // interesting symbols across call boundaries. if (NextNode) { @@ -1457,7 +1457,7 @@ static bool GenerateExtensivePathDiagnostic(PathDiagnostic& PD, if (const Stmt *Term = BE->getSrc()->getTerminator()) { // Are we jumping past the loop body without ever executing the // loop (because the condition was false)? - if (isLoopJumpPastBody(Term, BE) && + if (isLoopJumpPastBody(Term, &*BE) && !PD.getActivePath().empty() && PD.getActivePath().front() != LastLoopDiagnostic.second && Term != LastLoopDiagnostic.first) @@ -1480,7 +1480,7 @@ static bool GenerateExtensivePathDiagnostic(PathDiagnostic& PD, break; } - if (const BlockEntrance *BE = dyn_cast(&P)) { + if (Optional BE = P.getAs()) { CFGElement First = BE->getFirstElement(); if (CFGStmt S = First.getAs()) { const Stmt *stmt = S.getStmt(); @@ -1700,7 +1700,7 @@ const Stmt *BugReport::getStmt() const { ProgramPoint ProgP = ErrorNode->getLocation(); const Stmt *S = NULL; - if (BlockEntrance *BE = dyn_cast(&ProgP)) { + if (Optional BE = ProgP.getAs()) { CFGBlock &Exit = ProgP.getLocationContext()->getCFG()->getExit(); if (BE->getBlock() == &Exit) S = GetPreviousStmt(ErrorNode); @@ -1744,7 +1744,7 @@ PathDiagnosticLocation BugReport::getLocation(const SourceManager &SM) const { if (const BinaryOperator *B = dyn_cast(S)) return PathDiagnosticLocation::createOperatorLoc(B, SM); - if (isa(ErrorNode->getLocation())) + if (ErrorNode->getLocation().getAs()) return PathDiagnosticLocation::createEnd(S, SM, LC); return PathDiagnosticLocation::createBegin(S, SM, LC); diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp index 05d187e..5dc8dfc 100644 --- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -164,10 +164,10 @@ public: // First, find when we processed the statement. do { - if (const CallExitEnd *CEE = Node->getLocationAs()) + if (Optional CEE = Node->getLocationAs()) if (CEE->getCalleeContext()->getCallSite() == S) break; - if (const StmtPoint *SP = Node->getLocationAs()) + if (Optional SP = Node->getLocationAs()) if (SP->getStmt() == S) break; @@ -175,12 +175,12 @@ public: } while (Node); // Next, step over any post-statement checks. - while (Node && isa(Node->getLocation())) + while (Node && Node->getLocation().getAs()) Node = Node->getFirstPred(); // Finally, see if we inlined the call. if (Node) { - if (const CallExitEnd *CEE = Node->getLocationAs()) { + if (Optional CEE = Node->getLocationAs()) { const StackFrameContext *CalleeContext = CEE->getCalleeContext(); if (CalleeContext->getCallSite() == S) { BR.markInteresting(CalleeContext); @@ -204,7 +204,7 @@ public: if (N->getLocationContext() != StackFrame) return 0; - const StmtPoint *SP = N->getLocationAs(); + Optional SP = N->getLocationAs(); if (!SP) return 0; @@ -276,7 +276,7 @@ public: BugReporterContext &BRC, BugReport &BR) { // Are we at the entry node for this call? - const CallEnter *CE = N->getLocationAs(); + Optional CE = N->getLocationAs(); if (!CE) return 0; @@ -363,7 +363,7 @@ PathDiagnosticPiece *FindLastStoreBRVisitor::VisitNode(const ExplodedNode *Succ, // First see if we reached the declaration of the region. if (const VarRegion *VR = dyn_cast(R)) { - if (const PostStmt *P = Pred->getLocationAs()) { + if (Optional P = Pred->getLocationAs()) { if (const DeclStmt *DS = P->getStmtAs()) { if (DS->getSingleDecl() == VR->getDecl()) { StoreSite = Pred; @@ -385,7 +385,7 @@ PathDiagnosticPiece *FindLastStoreBRVisitor::VisitNode(const ExplodedNode *Succ, // If this is an assignment expression, we can track the value // being assigned. - if (const PostStmt *P = Succ->getLocationAs()) + if (Optional P = Succ->getLocationAs()) if (const BinaryOperator *BO = P->getStmtAs()) if (BO->isAssignmentOp()) InitE = BO->getRHS(); @@ -394,7 +394,7 @@ PathDiagnosticPiece *FindLastStoreBRVisitor::VisitNode(const ExplodedNode *Succ, // FIXME: Handle CXXThisRegion as well. (This is not a priority because // 'this' should never be NULL, but this visitor isn't just for NULL and // UndefinedVal.) - if (const CallEnter *CE = Succ->getLocationAs()) { + if (Optional CE = Succ->getLocationAs()) { const VarRegion *VR = cast(R); const ParmVarDecl *Param = cast(VR->getDecl()); @@ -432,7 +432,7 @@ PathDiagnosticPiece *FindLastStoreBRVisitor::VisitNode(const ExplodedNode *Succ, SmallString<256> sbuf; llvm::raw_svector_ostream os(sbuf); - if (const PostStmt *PS = StoreSite->getLocationAs()) { + if (Optional PS = StoreSite->getLocationAs()) { const Stmt *S = PS->getStmt(); const char *action = 0; const DeclStmt *DS = dyn_cast(S); @@ -494,7 +494,7 @@ PathDiagnosticPiece *FindLastStoreBRVisitor::VisitNode(const ExplodedNode *Succ, } } } - } else if (isa(StoreSite->getLocation())) { + } else if (StoreSite->getLocation().getAs()) { const ParmVarDecl *Param = cast(cast(R)->getDecl()); os << "Passing "; @@ -553,7 +553,7 @@ PathDiagnosticPiece *FindLastStoreBRVisitor::VisitNode(const ExplodedNode *Succ, // Construct a new PathDiagnosticPiece. ProgramPoint P = StoreSite->getLocation(); PathDiagnosticLocation L; - if (isa(P)) + if (P.getAs()) L = PathDiagnosticLocation(InitE, BRC.getSourceManager(), P.getLocationContext()); else @@ -633,15 +633,15 @@ bool bugreporter::trackNullOrUndefValue(const ExplodedNode *N, const Stmt *S, S = OVE->getSourceExpr(); if (IsArg) { - assert(isa(N->getLocation()) && "Tracking arg but not at call"); + assert(N->getLocation().getAs() && "Tracking arg but not at call"); } else { // Walk through nodes until we get one that matches the statement exactly. do { const ProgramPoint &pp = N->getLocation(); - if (const PostStmt *ps = dyn_cast(&pp)) { + if (Optional ps = pp.getAs()) { if (ps->getStmt() == S) break; - } else if (const CallExitEnd *CEE = dyn_cast(&pp)) { + } else if (Optional CEE = pp.getAs()) { if (CEE->getCalleeContext()->getCallSite() == S) break; } @@ -755,7 +755,7 @@ PathDiagnosticPiece *NilReceiverBRVisitor::VisitNode(const ExplodedNode *N, const ExplodedNode *PrevN, BugReporterContext &BRC, BugReport &BR) { - const PostStmt *P = N->getLocationAs(); + Optional P = N->getLocationAs(); if (!P) return 0; const ObjCMessageExpr *ME = P->getStmtAs(); @@ -860,14 +860,14 @@ PathDiagnosticPiece *ConditionBRVisitor::VisitNodeImpl(const ExplodedNode *N, // If an assumption was made on a branch, it should be caught // here by looking at the state transition. - if (const BlockEdge *BE = dyn_cast(&progPoint)) { + if (Optional BE = progPoint.getAs()) { const CFGBlock *srcBlk = BE->getSrc(); if (const Stmt *term = srcBlk->getTerminator()) return VisitTerminator(term, N, srcBlk, BE->getDst(), BR, BRC); return 0; } - if (const PostStmt *PS = dyn_cast(&progPoint)) { + if (Optional PS = progPoint.getAs()) { // FIXME: Assuming that BugReporter is a GRBugReporter is a layering // violation. const std::pair &tags = @@ -1216,7 +1216,7 @@ UndefOrNullArgVisitor::VisitNode(const ExplodedNode *N, ProgramPoint ProgLoc = N->getLocation(); // We are only interested in visiting CallEnter nodes. - CallEnter *CEnter = dyn_cast(&ProgLoc); + Optional CEnter = ProgLoc.getAs(); if (!CEnter) return 0; diff --git a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp index 5d819ba..894365c 100644 --- a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp @@ -114,7 +114,7 @@ namespace { } virtual void enqueue(const WorkListUnit& U) { - if (isa(U.getNode()->getLocation())) + if (U.getNode()->getLocation().getAs()) Queue.push_front(U); else Stack.push_back(U); @@ -230,11 +230,11 @@ void CoreEngine::dispatchWorkItem(ExplodedNode* Pred, ProgramPoint Loc, // Dispatch on the location type. switch (Loc.getKind()) { case ProgramPoint::BlockEdgeKind: - HandleBlockEdge(cast(Loc), Pred); + HandleBlockEdge(Loc.castAs(), Pred); break; case ProgramPoint::BlockEntranceKind: - HandleBlockEntrance(cast(Loc), Pred); + HandleBlockEntrance(Loc.castAs(), Pred); break; case ProgramPoint::BlockExitKind: @@ -242,7 +242,7 @@ void CoreEngine::dispatchWorkItem(ExplodedNode* Pred, ProgramPoint Loc, break; case ProgramPoint::CallEnterKind: { - CallEnter CEnter = cast(Loc); + CallEnter CEnter = Loc.castAs(); SubEng.processCallEnter(CEnter, Pred); break; } @@ -259,10 +259,10 @@ void CoreEngine::dispatchWorkItem(ExplodedNode* Pred, ProgramPoint Loc, break; } default: - assert(isa(Loc) || - isa(Loc) || - isa(Loc) || - isa(Loc)); + assert(Loc.getAs() || + Loc.getAs() || + Loc.getAs() || + Loc.getAs()); HandlePostStmt(WU.getBlock(), WU.getIndex(), Pred); break; } @@ -495,7 +495,7 @@ void CoreEngine::enqueueStmtNode(ExplodedNode *N, assert (!N->isSink()); // Check if this node entered a callee. - if (isa(N->getLocation())) { + if (N->getLocation().getAs()) { // Still use the index of the CallExpr. It's needed to create the callee // StackFrameContext. WList->enqueue(N, Block, Idx); @@ -503,13 +503,13 @@ void CoreEngine::enqueueStmtNode(ExplodedNode *N, } // Do not create extra nodes. Move to the next CFG element. - if (isa(N->getLocation()) || - isa(N->getLocation())) { + if (N->getLocation().getAs() || + N->getLocation().getAs()) { WList->enqueue(N, Block, Idx+1); return; } - if (isa(N->getLocation())) { + if (N->getLocation().getAs()) { WList->enqueue(N, Block, Idx); return; } diff --git a/clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp b/clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp index d64078f..a72f49d 100644 --- a/clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp @@ -85,11 +85,11 @@ bool ExplodedGraph::shouldCollect(const ExplodedNode *node) { // Condition 3. ProgramPoint progPoint = node->getLocation(); - if (!isa(progPoint) || isa(progPoint)) + if (!progPoint.getAs() || progPoint.getAs()) return false; // Condition 4. - PostStmt ps = cast(progPoint); + PostStmt ps = progPoint.castAs(); if (ps.getTag()) return false; @@ -114,7 +114,7 @@ bool ExplodedGraph::shouldCollect(const ExplodedNode *node) { // Condition 9. const ProgramPoint SuccLoc = succ->getLocation(); - if (const StmtPoint *SP = dyn_cast(&SuccLoc)) + if (Optional SP = SuccLoc.getAs()) if (CallEvent::isCallStmt(SP->getStmt())) return false; diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp index 3e5fd06..06b1db5 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -250,7 +250,7 @@ static bool shouldRemoveDeadBindings(AnalysisManager &AMgr, return false; // Is this the beginning of a basic block? - if (isa(Pred->getLocation())) + if (Pred->getLocation().getAs()) return true; // Is this on a non-expression? @@ -1056,11 +1056,11 @@ bool ExprEngine::replayWithoutInlining(ExplodedNode *N, // processing the call. if (L.isPurgeKind()) continue; - if (isa(&L)) + if (L.getAs()) continue; - if (isa(&L)) + if (L.getAs()) continue; - if (const StmtPoint *SP = dyn_cast(&L)) + if (Optional SP = L.getAs()) if (SP->getStmt() == CE) continue; break; @@ -1953,7 +1953,7 @@ void ExprEngine::evalEagerlyAssumeBinOpBifurcation(ExplodedNodeSet &Dst, // when the expression fails to evaluate to anything meaningful and // (as an optimization) we don't generate a node. ProgramPoint P = Pred->getLocation(); - if (!isa(P) || cast(P).getStmt() != Ex) { + if (!P.getAs() || P.castAs().getStmt() != Ex) { continue; } @@ -2073,7 +2073,7 @@ struct DOTGraphTraits : switch (Loc.getKind()) { case ProgramPoint::BlockEntranceKind: { Out << "Block Entrance: B" - << cast(Loc).getBlock()->getBlockID(); + << Loc.castAs().getBlock()->getBlockID(); if (const NamedDecl *ND = dyn_cast(Loc.getLocationContext()->getDecl())) { Out << " ("; @@ -2112,27 +2112,27 @@ struct DOTGraphTraits : break; case ProgramPoint::PreImplicitCallKind: { - ImplicitCallPoint *PC = cast(&Loc); + ImplicitCallPoint PC = Loc.castAs(); Out << "PreCall: "; // FIXME: Get proper printing options. - PC->getDecl()->print(Out, LangOptions()); - printLocation(Out, PC->getLocation()); + PC.getDecl()->print(Out, LangOptions()); + printLocation(Out, PC.getLocation()); break; } case ProgramPoint::PostImplicitCallKind: { - ImplicitCallPoint *PC = cast(&Loc); + ImplicitCallPoint PC = Loc.castAs(); Out << "PostCall: "; // FIXME: Get proper printing options. - PC->getDecl()->print(Out, LangOptions()); - printLocation(Out, PC->getLocation()); + PC.getDecl()->print(Out, LangOptions()); + printLocation(Out, PC.getLocation()); break; } default: { - if (StmtPoint *L = dyn_cast(&Loc)) { + if (Optional L = Loc.getAs()) { const Stmt *S = L->getStmt(); Out << S->getStmtClassName() << ' ' << (const void*) S << ' '; @@ -2140,13 +2140,13 @@ struct DOTGraphTraits : S->printPretty(Out, 0, PrintingPolicy(LO)); printLocation(Out, S->getLocStart()); - if (isa(Loc)) + if (Loc.getAs()) Out << "\\lPreStmt\\l;"; - else if (isa(Loc)) + else if (Loc.getAs()) Out << "\\lPostLoad\\l;"; - else if (isa(Loc)) + else if (Loc.getAs()) Out << "\\lPostStore\\l"; - else if (isa(Loc)) + else if (Loc.getAs()) Out << "\\lPostLValue\\l"; #if 0 @@ -2173,7 +2173,7 @@ struct DOTGraphTraits : break; } - const BlockEdge &E = cast(Loc); + const BlockEdge &E = Loc.castAs(); Out << "Edge: (B" << E.getSrc()->getBlockID() << ", B" << E.getDst()->getBlockID() << ')'; diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp index 5b3a518..b656bbd 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp @@ -523,16 +523,16 @@ void ExprEngine::VisitLogicalExpr(const BinaryOperator* B, ExplodedNode *Pred, ProgramStateRef state = Pred->getState(); ExplodedNode *N = Pred; - while (!isa(N->getLocation())) { + while (!N->getLocation().getAs()) { ProgramPoint P = N->getLocation(); - assert(isa(P)|| isa(P)); + assert(P.getAs()|| P.getAs()); (void) P; assert(N->pred_size() == 1); N = *N->pred_begin(); } assert(N->pred_size() == 1); N = *N->pred_begin(); - BlockEdge BE = cast(N->getLocation()); + BlockEdge BE = N->getLocation().castAs(); SVal X; // Determine the value of the expression by introspecting how we @@ -643,11 +643,11 @@ void ExprEngine::VisitGuardedExpr(const Expr *Ex, for (const ExplodedNode *N = Pred ; N ; N = *N->pred_begin()) { ProgramPoint PP = N->getLocation(); - if (isa(PP) || isa(PP)) { + if (PP.getAs() || PP.getAs()) { assert(N->pred_size() == 1); continue; } - SrcBlock = cast(&PP)->getSrc(); + SrcBlock = PP.castAs().getSrc(); break; } diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp index 0d4673c..a4d33ee 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp @@ -77,10 +77,10 @@ static std::pairgetLocation(); if (PP.getLocationContext()->getCurrentStackFrame() == SF) { - if (const StmtPoint *SP = dyn_cast(&PP)) { + if (Optional SP = PP.getAs()) { S = SP->getStmt(); break; - } else if (const CallExitEnd *CEE = dyn_cast(&PP)) { + } else if (Optional CEE = PP.getAs()) { S = CEE->getCalleeContext()->getCallSite(); if (S) break; @@ -88,17 +88,17 @@ static std::pair CE; do { Node = Node->getFirstPred(); CE = Node->getLocationAs(); } while (!CE || CE->getCalleeContext() != CEE->getCalleeContext()); // Continue searching the graph. - } else if (const BlockEdge *BE = dyn_cast(&PP)) { + } else if (Optional BE = PP.getAs()) { Blk = BE->getSrc(); } - } else if (const CallEnter *CE = dyn_cast(&PP)) { + } else if (Optional CE = PP.getAs()) { // If we reached the CallEnter for this function, it has no statements. if (CE->getCalleeContext() == SF) break; diff --git a/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp b/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp index 12d85db..b27a80f 100644 --- a/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp +++ b/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp @@ -583,29 +583,24 @@ PathDiagnosticLocation const SourceManager &SMng) { const Stmt* S = 0; - if (const BlockEdge *BE = dyn_cast(&P)) { + if (Optional BE = P.getAs()) { const CFGBlock *BSrc = BE->getSrc(); S = BSrc->getTerminatorCondition(); - } - else if (const StmtPoint *SP = dyn_cast(&P)) { + } else if (Optional SP = P.getAs()) { S = SP->getStmt(); - if (isa(P)) + if (P.getAs()) return PathDiagnosticLocation::createEnd(S, SMng, P.getLocationContext()); - } - else if (const PostImplicitCall *PIE = dyn_cast(&P)) { + } else if (Optional PIE = P.getAs()) { return PathDiagnosticLocation(PIE->getLocation(), SMng); - } - else if (const CallEnter *CE = dyn_cast(&P)) { + } else if (Optional CE = P.getAs()) { return getLocationForCaller(CE->getCalleeContext(), CE->getLocationContext(), SMng); - } - else if (const CallExitEnd *CEE = dyn_cast(&P)) { + } else if (Optional CEE = P.getAs()) { return getLocationForCaller(CEE->getCalleeContext(), CEE->getLocationContext(), SMng); - } - else { + } else { llvm_unreachable("Unexpected ProgramPoint"); } @@ -622,13 +617,13 @@ PathDiagnosticLocation while (NI) { ProgramPoint P = NI->getLocation(); - if (const StmtPoint *PS = dyn_cast(&P)) { + if (Optional PS = P.getAs()) { S = PS->getStmt(); - if (isa(P)) + if (P.getAs()) return PathDiagnosticLocation::createEnd(S, SM, NI->getLocationContext()); break; - } else if (const BlockEdge *BE = dyn_cast(&P)) { + } else if (Optional BE = P.getAs()) { S = BE->getSrc()->getTerminator(); break; } @@ -998,7 +993,7 @@ StackHintGenerator::~StackHintGenerator() {} std::string StackHintGeneratorForSymbol::getMessage(const ExplodedNode *N){ ProgramPoint P = N->getLocation(); - const CallExitEnd *CExit = dyn_cast(&P); + Optional CExit = P.getAs(); assert(CExit && "Stack Hints should be constructed at CallExitEnd points."); // FIXME: Use CallEvent to abstract this over all calls.