aboutsummaryrefslogtreecommitdiff
path: root/include/clang
diff options
context:
space:
mode:
authorZhongxing Xu <xuzhongxing@gmail.com>2010-07-19 01:31:21 +0000
committerZhongxing Xu <xuzhongxing@gmail.com>2010-07-19 01:31:21 +0000
commitc6238d2786cfd961b94580b3d3675a1b3ff0721c (patch)
tree22875d45e9365f67986a5d837d2c886788f192f5 /include/clang
parent0bbad519aa068206f1e158d5073f72a39fbe83c5 (diff)
Reapply r108617.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108668 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang')
-rw-r--r--include/clang/Analysis/AnalysisContext.h21
-rw-r--r--include/clang/Analysis/ProgramPoint.h12
-rw-r--r--include/clang/Checker/PathSensitive/AnalysisManager.h37
-rw-r--r--include/clang/Checker/PathSensitive/GRCoreEngine.h10
4 files changed, 61 insertions, 19 deletions
diff --git a/include/clang/Analysis/AnalysisContext.h b/include/clang/Analysis/AnalysisContext.h
index 9ebd93b75b..584173a33f 100644
--- a/include/clang/Analysis/AnalysisContext.h
+++ b/include/clang/Analysis/AnalysisContext.h
@@ -34,11 +34,16 @@ class ImplicitParamDecl;
class LocationContextManager;
class StackFrameContext;
+namespace idx { class TranslationUnit; }
+
/// AnalysisContext contains the context data for the function or method under
/// analysis.
class AnalysisContext {
const Decl *D;
+ // TranslationUnit is NULL if we don't have multiple translation units.
+ const idx::TranslationUnit *TU;
+
// AnalysisContext owns the following data.
CFG *cfg;
bool builtCFG;
@@ -48,14 +53,18 @@ class AnalysisContext {
llvm::BumpPtrAllocator A;
bool AddEHEdges;
public:
- AnalysisContext(const Decl *d, bool addehedges = false)
- : D(d), cfg(0), builtCFG(false), liveness(0), PM(0),
+ AnalysisContext(const Decl *d, const idx::TranslationUnit *tu,
+ bool addehedges = false)
+ : D(d), TU(tu), cfg(0), builtCFG(false), liveness(0), PM(0),
ReferencedBlockVars(0), AddEHEdges(addehedges) {}
~AnalysisContext();
ASTContext &getASTContext() { return D->getASTContext(); }
- const Decl *getDecl() { return D; }
+ const Decl *getDecl() const { return D; }
+
+ const idx::TranslationUnit *getTranslationUnit() const { return TU; }
+
/// getAddEHEdges - Return true iff we are adding exceptional edges from
/// callExprs. If this is false, then try/catch statements and blocks
/// reachable from them can appear to be dead in the CFG, analysis passes must
@@ -82,7 +91,7 @@ class AnalysisContextManager {
public:
~AnalysisContextManager();
- AnalysisContext *getContext(const Decl *D);
+ AnalysisContext *getContext(const Decl *D,const idx::TranslationUnit *TU = 0);
// Discard all previously created AnalysisContexts.
void clear();
@@ -109,6 +118,10 @@ public:
AnalysisContext *getAnalysisContext() const { return Ctx; }
+ const idx::TranslationUnit *getTranslationUnit() const {
+ return Ctx->getTranslationUnit();
+ }
+
const LocationContext *getParent() const { return Parent; }
bool isParentOf(const LocationContext *LC) const;
diff --git a/include/clang/Analysis/ProgramPoint.h b/include/clang/Analysis/ProgramPoint.h
index 075838d45e..24bbf22640 100644
--- a/include/clang/Analysis/ProgramPoint.h
+++ b/include/clang/Analysis/ProgramPoint.h
@@ -15,6 +15,7 @@
#ifndef LLVM_CLANG_ANALYSIS_PROGRAM_POINT
#define LLVM_CLANG_ANALYSIS_PROGRAM_POINT
+#include "clang/Analysis/AnalysisContext.h"
#include "clang/Analysis/CFG.h"
#include "llvm/System/DataTypes.h"
#include "llvm/ADT/DenseMap.h"
@@ -26,6 +27,7 @@
namespace clang {
class LocationContext;
+class AnalysisContext;
class FunctionDecl;
class ProgramPoint {
@@ -313,16 +315,16 @@ public:
class CallEnter : public StmtPoint {
public:
- // CallEnter uses the caller's location context.
- CallEnter(const Stmt *S, const FunctionDecl *fd, const LocationContext *L)
- : StmtPoint(S, fd, CallEnterKind, L, 0) {}
+ // L is caller's location context. AC is callee's AnalysisContext.
+ CallEnter(const Stmt *S, const AnalysisContext *AC, const LocationContext *L)
+ : StmtPoint(S, AC, CallEnterKind, L, 0) {}
const Stmt *getCallExpr() const {
return static_cast<const Stmt *>(getData1());
}
- const FunctionDecl *getCallee() const {
- return static_cast<const FunctionDecl *>(getData2());
+ const AnalysisContext *getCalleeContext() const {
+ return static_cast<const AnalysisContext *>(getData2());
}
static bool classof(const ProgramPoint *Location) {
diff --git a/include/clang/Checker/PathSensitive/AnalysisManager.h b/include/clang/Checker/PathSensitive/AnalysisManager.h
index 3c7cb68c09..3f673618cf 100644
--- a/include/clang/Checker/PathSensitive/AnalysisManager.h
+++ b/include/clang/Checker/PathSensitive/AnalysisManager.h
@@ -21,6 +21,11 @@
namespace clang {
+namespace idx {
+ class Indexer;
+ class TranslationUnit;
+}
+
class AnalysisManager : public BugReporterData {
AnalysisContextManager AnaCtxMgr;
LocationContextManager LocCtxMgr;
@@ -35,6 +40,11 @@ class AnalysisManager : public BugReporterData {
StoreManagerCreator CreateStoreMgr;
ConstraintManagerCreator CreateConstraintMgr;
+ /// \brief Provide function definitions in other translation units. This is
+ /// NULL if we don't have multiple translation units. AnalysisManager does
+ /// not own the Indexer.
+ idx::Indexer *Idxer;
+
enum AnalysisScope { ScopeTU, ScopeDecl } AScope;
// The maximum number of exploded nodes the analyzer will generate.
@@ -62,13 +72,14 @@ public:
AnalysisManager(ASTContext &ctx, Diagnostic &diags,
const LangOptions &lang, PathDiagnosticClient *pd,
StoreManagerCreator storemgr,
- ConstraintManagerCreator constraintmgr, unsigned maxnodes,
- unsigned maxloop,
+ ConstraintManagerCreator constraintmgr,
+ idx::Indexer *idxer,
+ unsigned maxnodes, unsigned maxloop,
bool vizdot, bool vizubi, bool purge, bool eager, bool trim,
bool inlinecall)
: Ctx(ctx), Diags(diags), LangInfo(lang), PD(pd),
- CreateStoreMgr(storemgr), CreateConstraintMgr(constraintmgr),
+ CreateStoreMgr(storemgr), CreateConstraintMgr(constraintmgr),Idxer(idxer),
AScope(ScopeDecl), MaxNodes(maxnodes), MaxLoop(maxloop),
VisualizeEGDot(vizdot), VisualizeEGUbi(vizubi), PurgeDead(purge),
EagerlyAssume(eager), TrimGraph(trim), InlineCall(inlinecall) {}
@@ -133,6 +144,10 @@ public:
bool shouldInlineCall() const { return InlineCall; }
+ bool hasIndexer() const { return Idxer != 0; }
+
+ const AnalysisContext *getAnalysisContextInAnotherTU(const Decl *D);
+
CFG *getCFG(Decl const *D) {
return AnaCtxMgr.getContext(D)->getCFG();
}
@@ -145,9 +160,21 @@ public:
return AnaCtxMgr.getContext(D)->getParentMap();
}
+ const AnalysisContext *getAnalysisContext(const Decl *D) {
+ return AnaCtxMgr.getContext(D);
+ }
+
+ const StackFrameContext *getStackFrame(AnalysisContext *Ctx,
+ LocationContext const *Parent,
+ Stmt const *S, const CFGBlock *Blk,
+ unsigned Idx) {
+ return LocCtxMgr.getStackFrame(Ctx, Parent, S, Blk, Idx);
+ }
+
// Get the top level stack frame.
- const StackFrameContext *getStackFrame(Decl const *D) {
- return LocCtxMgr.getStackFrame(AnaCtxMgr.getContext(D), 0, 0, 0, 0);
+ const StackFrameContext *getStackFrame(Decl const *D,
+ const idx::TranslationUnit *TU) {
+ return LocCtxMgr.getStackFrame(AnaCtxMgr.getContext(D, TU), 0, 0, 0, 0);
}
// Get a stack frame with parent.
diff --git a/include/clang/Checker/PathSensitive/GRCoreEngine.h b/include/clang/Checker/PathSensitive/GRCoreEngine.h
index 7f101dca97..317558e962 100644
--- a/include/clang/Checker/PathSensitive/GRCoreEngine.h
+++ b/include/clang/Checker/PathSensitive/GRCoreEngine.h
@@ -442,8 +442,8 @@ class GRCallEnterNodeBuilder {
// The call site.
const Stmt *CE;
- // The definition of callee.
- const FunctionDecl *FD;
+ // The AnalysisContext of the callee.
+ const AnalysisContext *CalleeCtx;
// The parent block of the CallExpr.
const CFGBlock *Block;
@@ -453,9 +453,9 @@ class GRCallEnterNodeBuilder {
public:
GRCallEnterNodeBuilder(GRCoreEngine &eng, const ExplodedNode *pred,
- const Stmt *s, const FunctionDecl *fd,
+ const Stmt *s, const AnalysisContext *callee,
const CFGBlock *blk, unsigned idx)
- : Eng(eng), Pred(pred), CE(s), FD(fd), Block(blk), Index(idx) {}
+ : Eng(eng), Pred(pred), CE(s), CalleeCtx(callee), Block(blk), Index(idx) {}
const GRState *getState() const { return Pred->getState(); }
@@ -465,7 +465,7 @@ public:
const Stmt *getCallExpr() const { return CE; }
- const FunctionDecl *getCallee() const { return FD; }
+ const AnalysisContext *getCalleeContext() const { return CalleeCtx; }
const CFGBlock *getBlock() const { return Block; }