Skip to content

Commit 5d30c69

Browse files
committed
Add skeleton for handling other kinds of CFGElements.
llvm-svn: 119135
1 parent efacb9e commit 5d30c69

File tree

6 files changed

+53
-19
lines changed

6 files changed

+53
-19
lines changed

clang/include/clang/Analysis/CFG.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class CFGElement {
4949
Statement,
5050
StatementAsLValue,
5151
Initializer,
52-
Dtor,
52+
ImplicitDtor,
5353
// dtor kind
5454
AutomaticObjectDtor,
5555
BaseDtor,
@@ -74,7 +74,7 @@ class CFGElement {
7474
Kind getKind() const { return static_cast<Kind>(Data1.getInt()); }
7575

7676
Kind getDtorKind() const {
77-
assert(getKind() == Dtor);
77+
assert(getKind() == ImplicitDtor);
7878
return static_cast<Kind>(Data2.getInt() + DTOR_BEGIN);
7979
}
8080

@@ -132,13 +132,13 @@ class CFGInitializer : public CFGElement {
132132
class CFGImplicitDtor : public CFGElement {
133133
protected:
134134
CFGImplicitDtor(unsigned K, void* P, void* S)
135-
: CFGElement(P, Dtor, S, K - DTOR_BEGIN) {}
135+
: CFGElement(P, ImplicitDtor, S, K - DTOR_BEGIN) {}
136136

137137
public:
138138
CFGImplicitDtor() {}
139139

140140
static bool classof(const CFGElement *E) {
141-
return E->getKind() == Dtor;
141+
return E->getKind() == ImplicitDtor;
142142
}
143143
};
144144

@@ -161,7 +161,8 @@ class CFGAutomaticObjDtor: public CFGImplicitDtor {
161161
}
162162

163163
static bool classof(const CFGElement *E) {
164-
return E->getKind() == Dtor && E->getDtorKind() == AutomaticObjectDtor;
164+
return E->getKind() == ImplicitDtor &&
165+
E->getDtorKind() == AutomaticObjectDtor;
165166
}
166167
};
167168

@@ -178,7 +179,7 @@ class CFGBaseDtor : public CFGImplicitDtor {
178179
}
179180

180181
static bool classof(const CFGElement *E) {
181-
return E->getKind() == Dtor && E->getDtorKind() == BaseDtor;
182+
return E->getKind() == ImplicitDtor && E->getDtorKind() == BaseDtor;
182183
}
183184
};
184185

@@ -195,7 +196,7 @@ class CFGMemberDtor : public CFGImplicitDtor {
195196
}
196197

197198
static bool classof(const CFGElement *E) {
198-
return E->getKind() == Dtor && E->getDtorKind() == MemberDtor;
199+
return E->getKind() == ImplicitDtor && E->getDtorKind() == MemberDtor;
199200
}
200201
};
201202

@@ -212,7 +213,7 @@ class CFGTemporaryDtor : public CFGImplicitDtor {
212213
}
213214

214215
static bool classof(const CFGElement *E) {
215-
return E->getKind() == Dtor && E->getDtorKind() == TemporaryDtor;
216+
return E->getKind() == ImplicitDtor && E->getDtorKind() == TemporaryDtor;
216217
}
217218
};
218219

clang/include/clang/Checker/PathSensitive/GRCoreEngine.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ class GRCoreEngine {
9090
SubEngine.ProcessEndPath(Builder);
9191
}
9292

93-
void ProcessStmt(const CFGElement E, GRStmtNodeBuilder& Builder) {
94-
SubEngine.ProcessStmt(E, Builder);
93+
void ProcessElement(const CFGElement E, GRStmtNodeBuilder& Builder) {
94+
SubEngine.ProcessElement(E, Builder);
9595
}
9696

9797
bool ProcessBlockEntrance(const CFGBlock* Blk, const ExplodedNode *Pred,

clang/include/clang/Checker/PathSensitive/GRExprEngine.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,15 @@ class GRExprEngine : public GRSubEngine {
175175
return static_cast<CHECKER*>(lookupChecker(CHECKER::getTag()));
176176
}
177177

178-
/// ProcessStmt - Called by GRCoreEngine. Used to generate new successor
179-
/// nodes by processing the 'effects' of a block-level statement.
180-
void ProcessStmt(const CFGElement E, GRStmtNodeBuilder& builder);
178+
/// ProcessElement - Called by GRCoreEngine. Used to generate new successor
179+
/// nodes by processing the 'effects' of a CFG element.
180+
void ProcessElement(const CFGElement E, GRStmtNodeBuilder& builder);
181+
182+
void ProcessStmt(const CFGStmt S, GRStmtNodeBuilder &builder);
183+
184+
void ProcessInitializer(const CFGInitializer I, GRStmtNodeBuilder &builder);
185+
186+
void ProcessImplicitDtor(const CFGImplicitDtor D, GRStmtNodeBuilder &builder);
181187

182188
/// ProcessBlockEntrance - Called by GRCoreEngine when start processing
183189
/// a CFGBlock. This method returns true if the analysis should continue

clang/include/clang/Checker/PathSensitive/GRSubEngine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class GRSubEngine {
4747

4848
/// Called by GRCoreEngine. Used to generate new successor
4949
/// nodes by processing the 'effects' of a block-level statement.
50-
virtual void ProcessStmt(const CFGElement E, GRStmtNodeBuilder& builder) = 0;
50+
virtual void ProcessElement(const CFGElement E, GRStmtNodeBuilder& builder)=0;
5151

5252
/// Called by GRCoreEngine when start processing
5353
/// a CFGBlock. This method returns true if the analysis should continue

clang/lib/Checker/GRCoreEngine.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ void GRCoreEngine::HandleBlockEntrance(const BlockEntrance& L,
309309
if (CFGElement E = L.getFirstElement()) {
310310
GRStmtNodeBuilder Builder(L.getBlock(), 0, Pred, this,
311311
SubEngine.getStateManager());
312-
ProcessStmt(E, Builder);
312+
ProcessElement(E, Builder);
313313
}
314314
else
315315
HandleBlockExit(L.getBlock(), Pred);
@@ -423,7 +423,7 @@ void GRCoreEngine::HandlePostStmt(const PostStmt& L, const CFGBlock* B,
423423
else {
424424
GRStmtNodeBuilder Builder(B, StmtIdx, Pred, this,
425425
SubEngine.getStateManager());
426-
ProcessStmt((*B)[StmtIdx], Builder);
426+
ProcessElement((*B)[StmtIdx], Builder);
427427
}
428428
}
429429

clang/lib/Checker/GRExprEngine.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,27 @@ void GRExprEngine::ProcessEndWorklist(bool hasWorkRemaining) {
552552
}
553553
}
554554

555-
void GRExprEngine::ProcessStmt(const CFGElement CE,GRStmtNodeBuilder& builder) {
556-
CurrentStmt = CE.getAs<CFGStmt>();
555+
void GRExprEngine::ProcessElement(const CFGElement E,
556+
GRStmtNodeBuilder& builder) {
557+
switch (E.getKind()) {
558+
case CFGElement::Statement:
559+
case CFGElement::StatementAsLValue:
560+
ProcessStmt(E.getAs<CFGStmt>(), builder);
561+
break;
562+
case CFGElement::Initializer:
563+
ProcessInitializer(E.getAs<CFGInitializer>(), builder);
564+
break;
565+
case CFGElement::ImplicitDtor:
566+
ProcessImplicitDtor(E.getAs<CFGImplicitDtor>(), builder);
567+
break;
568+
default:
569+
// Suppress compiler warning.
570+
llvm_unreachable("Unexpected CFGElement kind.");
571+
}
572+
}
573+
574+
void GRExprEngine::ProcessStmt(const CFGStmt S, GRStmtNodeBuilder& builder) {
575+
CurrentStmt = S.getStmt();
557576
PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(),
558577
CurrentStmt->getLocStart(),
559578
"Error evaluating statement");
@@ -636,7 +655,7 @@ void GRExprEngine::ProcessStmt(const CFGElement CE,GRStmtNodeBuilder& builder) {
636655
Builder->SetCleanedState(*I == EntryNode ? CleanedState : GetState(*I));
637656

638657
// Visit the statement.
639-
if (CE.getAs<CFGStmt>().asLValue())
658+
if (S.asLValue())
640659
VisitLValue(cast<Expr>(CurrentStmt), *I, Dst);
641660
else
642661
Visit(CurrentStmt, *I, Dst);
@@ -660,6 +679,14 @@ void GRExprEngine::ProcessStmt(const CFGElement CE,GRStmtNodeBuilder& builder) {
660679
Builder = NULL;
661680
}
662681

682+
void GRExprEngine::ProcessInitializer(const CFGInitializer I,
683+
GRStmtNodeBuilder &builder) {
684+
}
685+
686+
void GRExprEngine::ProcessImplicitDtor(const CFGImplicitDtor D,
687+
GRStmtNodeBuilder &builder) {
688+
}
689+
663690
void GRExprEngine::Visit(const Stmt* S, ExplodedNode* Pred,
664691
ExplodedNodeSet& Dst) {
665692
PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(),

0 commit comments

Comments
 (0)