Have BugReporter::getCFG and BugReporter::getLiveVariables returns pointers instead of references, because they can both fail

on functions we cannot construct full CFGs for yet.

llvm-svn: 53081
This commit is contained in:
Ted Kremenek 2008-07-03 05:26:14 +00:00
parent 590afde872
commit 1d3c797c90
4 changed files with 40 additions and 26 deletions

View File

@ -123,9 +123,9 @@ namespace {
Decl* getCodeDecl() const { return D; } Decl* getCodeDecl() const { return D; }
Stmt* getBody() const { return Body; } Stmt* getBody() const { return Body; }
virtual CFG& getCFG() { virtual CFG* getCFG() {
if (!cfg) cfg.reset(CFG::buildCFG(getBody())); if (!cfg) cfg.reset(CFG::buildCFG(getBody()));
return *cfg.get(); return cfg.get();
} }
virtual ParentMap& getParentMap() { virtual ParentMap& getParentMap() {
@ -157,14 +157,17 @@ namespace {
return C.PD.get(); return C.PD.get();
} }
virtual LiveVariables& getLiveVariables() { virtual LiveVariables* getLiveVariables() {
if (!liveness) { if (!liveness) {
liveness.reset(new LiveVariables(getCFG())); CFG* c = getCFG();
liveness->runOnCFG(getCFG()); if (!c) return 0;
liveness->runOnAllBlocks(getCFG(), 0, true);
liveness.reset(new LiveVariables(*c));
liveness->runOnCFG(*c);
liveness->runOnAllBlocks(*c, 0, true);
} }
return *liveness.get(); return liveness.get();
} }
bool shouldVisualize() const { bool shouldVisualize() const {
@ -285,27 +288,32 @@ void AnalysisConsumer::HandleCode(Decl* D, Stmt* Body, Actions actions) {
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
static void ActionDeadStores(AnalysisManager& mgr) { static void ActionDeadStores(AnalysisManager& mgr) {
if (LiveVariables* L = mgr.getLiveVariables()) {
BugReporter BR(mgr); BugReporter BR(mgr);
CheckDeadStores(mgr.getLiveVariables(), BR); CheckDeadStores(*L, BR);
}
} }
static void ActionUninitVals(AnalysisManager& mgr) { static void ActionUninitVals(AnalysisManager& mgr) {
CheckUninitializedValues(mgr.getCFG(), mgr.getContext(), if (CFG* c = mgr.getCFG())
mgr.getDiagnostic()); CheckUninitializedValues(*c, mgr.getContext(), mgr.getDiagnostic());
} }
static void ActionGRExprEngine(AnalysisManager& mgr, GRTransferFuncs* tf) { static void ActionGRExprEngine(AnalysisManager& mgr, GRTransferFuncs* tf) {
llvm::OwningPtr<GRTransferFuncs> TF(tf); llvm::OwningPtr<GRTransferFuncs> TF(tf);
// Construct the analysis engine.
LiveVariables* L = mgr.getLiveVariables();
if (!L) return;
// Display progress. // Display progress.
if (!mgr.shouldVisualize()) if (!mgr.shouldVisualize())
mgr.DisplayFunction(); mgr.DisplayFunction();
// Construct the analysis engine. GRExprEngine Eng(*mgr.getCFG(), *mgr.getCodeDecl(), mgr.getContext(), *L);
GRExprEngine Eng(mgr.getCFG(), *mgr.getCodeDecl(), mgr.getContext(),
mgr.getLiveVariables());
Eng.setTransferFunctions(tf); Eng.setTransferFunctions(tf);
// Execute the worklist algorithm. // Execute the worklist algorithm.
@ -355,18 +363,24 @@ static void ActionSimpleChecks(AnalysisManager& mgr) {
} }
static void ActionLiveness(AnalysisManager& mgr) { static void ActionLiveness(AnalysisManager& mgr) {
if (LiveVariables* L = mgr.getLiveVariables()) {
mgr.DisplayFunction(); mgr.DisplayFunction();
mgr.getLiveVariables().dumpBlockLiveness(mgr.getSourceManager()); L->dumpBlockLiveness(mgr.getSourceManager());
}
} }
static void ActionCFGDump(AnalysisManager& mgr) { static void ActionCFGDump(AnalysisManager& mgr) {
if (CFG* c = mgr.getCFG()) {
mgr.DisplayFunction(); mgr.DisplayFunction();
mgr.getCFG().dump(); c->dump();
}
} }
static void ActionCFGView(AnalysisManager& mgr) { static void ActionCFGView(AnalysisManager& mgr) {
if (CFG* c = mgr.getCFG()) {
mgr.DisplayFunction(); mgr.DisplayFunction();
mgr.getCFG().viewCFG(); c->viewCFG();
}
} }
static void ActionCheckObjCDealloc(AnalysisManager& mgr) { static void ActionCheckObjCDealloc(AnalysisManager& mgr) {

View File

@ -136,9 +136,9 @@ public:
virtual PathDiagnosticClient* getPathDiagnosticClient() = 0; virtual PathDiagnosticClient* getPathDiagnosticClient() = 0;
virtual ASTContext& getContext() = 0; virtual ASTContext& getContext() = 0;
virtual SourceManager& getSourceManager() = 0; virtual SourceManager& getSourceManager() = 0;
virtual CFG& getCFG() = 0; virtual CFG* getCFG() = 0;
virtual ParentMap& getParentMap() = 0; virtual ParentMap& getParentMap() = 0;
virtual LiveVariables& getLiveVariables() = 0; virtual LiveVariables* getLiveVariables() = 0;
}; };
class BugReporter { class BugReporter {
@ -173,7 +173,7 @@ public:
return D.getSourceManager(); return D.getSourceManager();
} }
CFG& getCFG() { CFG* getCFG() {
return D.getCFG(); return D.getCFG();
} }
@ -181,7 +181,7 @@ public:
return D.getParentMap(); return D.getParentMap();
} }
LiveVariables& getLiveVariables() { LiveVariables* getLiveVariables() {
return D.getLiveVariables(); return D.getLiveVariables();
} }

View File

@ -118,7 +118,7 @@ Stmt* BugReport::getStmt(BugReporter& BR) const {
Stmt *S = NULL; Stmt *S = NULL;
if (BlockEntrance* BE = dyn_cast<BlockEntrance>(&ProgP)) if (BlockEntrance* BE = dyn_cast<BlockEntrance>(&ProgP))
if (BE->getBlock() == &BR.getCFG().getExit()) if (BE->getBlock() == &BR.getCFG()->getExit())
S = GetLastStmt(EndNode); S = GetLastStmt(EndNode);
if (!S) if (!S)
S = GetStmt(ProgP); S = GetStmt(ProgP);

View File

@ -153,7 +153,7 @@ void clang::CheckDeadStores(LiveVariables& L, BugReporter& BR) {
DiagCollector C(BT); DiagCollector C(BT);
DeadStoreObs A(BR.getContext(), BR.getDiagnostic(), C, BR.getParentMap()); DeadStoreObs A(BR.getContext(), BR.getDiagnostic(), C, BR.getParentMap());
L.runOnAllBlocks(BR.getCFG(), &A); L.runOnAllBlocks(*BR.getCFG(), &A);
// Emit the bug reports. // Emit the bug reports.