From: Anna Zaks Date: Tue, 1 Nov 2011 22:41:14 +0000 (+0000) Subject: [analyzer] Fix PR11282 - an assert in markAsSink X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2d950b15b2b2b650b102ecf0c6b50b45e0cb6a8a;p=clang [analyzer] Fix PR11282 - an assert in markAsSink This is another fallout from the refactoring. We were calling MarkAsSink on a cached out node. (Fixes radar://10376675) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143516 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h b/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h index a3e5a19ab2..2079cdfaff 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h @@ -393,7 +393,7 @@ public: const CFGBlock *dstT, const CFGBlock *dstF) : NodeBuilder(SrcNode, DstSet, C), DstT(dstT), DstF(dstF), InFeasibleTrue(!DstT), InFeasibleFalse(!DstF) { - // The Banch node builder does not generate autotransitions. + // The branch node builder does not generate autotransitions. // If there are no successors it means that both branches are infeasible. takeNodes(SrcNode); } diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h b/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h index c824ff51cc..0e1cae9580 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h @@ -389,6 +389,7 @@ public: void clear() { Impl.clear(); } void insert(const ExplodedNodeSet &S) { + assert(&S != this); if (empty()) Impl = S.Impl; else diff --git a/lib/StaticAnalyzer/Core/CoreEngine.cpp b/lib/StaticAnalyzer/Core/CoreEngine.cpp index db007feafb..0003e6cd3f 100644 --- a/lib/StaticAnalyzer/Core/CoreEngine.cpp +++ b/lib/StaticAnalyzer/Core/CoreEngine.cpp @@ -546,14 +546,17 @@ ExplodedNode* NodeBuilder::generateNodeImpl(const ProgramPoint &Loc, ExplodedNode *N = C.Eng.G->getNode(Loc, State, &IsNew); N->addPredecessor(FromN, *C.Eng.G); Frontier.erase(FromN); + assert(IsNew || N->isSink() == MarkAsSink); + + if (!IsNew) + return 0; if (MarkAsSink) N->markAsSink(); - - if (IsNew && !MarkAsSink) + else Frontier.Add(N); - return (IsNew ? N : 0); + return N; } StmtNodeBuilder::~StmtNodeBuilder() { diff --git a/test/Analysis/misc-ps.c b/test/Analysis/misc-ps.c index be0bbf58ff..32475f0d0f 100644 --- a/test/Analysis/misc-ps.c +++ b/test/Analysis/misc-ps.c @@ -106,3 +106,17 @@ static int radar10367606(int t) { return 0; } +/* Caching out on a sink node. */ +extern int fooR10376675(); +extern int* bazR10376675(); +extern int nR10376675; +void barR10376675(int *x) { + int *pm; + if (nR10376675 * 2) { + int *pk = bazR10376675(); + pm = pk; //expected-warning {{never read}} + } + do { + *x = fooR10376675(); + } while (0); +}