[cfe-commits] r91991 - in /cfe/trunk: include/clang/Analysis/LocalCheckers.h include/clang/Analysis/PathSensitive/Checker.h include/clang/Analysis/PathSensitive/GRTransferFuncs.h lib/Analysis/CallInliner.cpp lib/Frontend/AnalysisConsumer.cpp
Zhongxing Xu
xuzhongxing at gmail.com
Wed Dec 23 00:56:19 PST 2009
Author: zhongxingxu
Date: Wed Dec 23 02:56:18 2009
New Revision: 91991
URL: http://llvm.org/viewvc/llvm-project?rev=91991&view=rev
Log:
Migrate the call inliner to the Checker interface.
Modified:
cfe/trunk/include/clang/Analysis/LocalCheckers.h
cfe/trunk/include/clang/Analysis/PathSensitive/Checker.h
cfe/trunk/include/clang/Analysis/PathSensitive/GRTransferFuncs.h
cfe/trunk/lib/Analysis/CallInliner.cpp
cfe/trunk/lib/Frontend/AnalysisConsumer.cpp
Modified: cfe/trunk/include/clang/Analysis/LocalCheckers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/LocalCheckers.h?rev=91991&r1=91990&r2=91991&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/LocalCheckers.h (original)
+++ cfe/trunk/include/clang/Analysis/LocalCheckers.h Wed Dec 23 02:56:18 2009
@@ -56,6 +56,8 @@
void CheckSecuritySyntaxOnly(const Decl *D, BugReporter &BR);
void CheckSizeofPointer(const Decl *D, BugReporter &BR);
+
+void RegisterCallInliner(GRExprEngine &Eng);
} // end namespace clang
#endif
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/Checker.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/Checker.h?rev=91991&r1=91990&r2=91991&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/Checker.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/Checker.h Wed Dec 23 02:56:18 2009
@@ -61,8 +61,12 @@
return Eng;
}
+ AnalysisManager &getAnalysisManager() {
+ return Eng.getAnalysisManager();
+ }
+
ConstraintManager &getConstraintManager() {
- return Eng.getConstraintManager();
+ return Eng.getConstraintManager();
}
StoreManager &getStoreManager() {
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/GRTransferFuncs.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/GRTransferFuncs.h?rev=91991&r1=91990&r2=91991&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRTransferFuncs.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRTransferFuncs.h Wed Dec 23 02:56:18 2009
@@ -80,9 +80,6 @@
return state;
}
};
-
-GRTransferFuncs *CreateCallInliner(ASTContext &ctx);
-
} // end clang namespace
#endif
Modified: cfe/trunk/lib/Analysis/CallInliner.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CallInliner.cpp?rev=91991&r1=91990&r2=91991&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CallInliner.cpp (original)
+++ cfe/trunk/lib/Analysis/CallInliner.cpp Wed Dec 23 02:56:18 2009
@@ -11,36 +11,43 @@
//
//===----------------------------------------------------------------------===//
-#include "clang/Analysis/PathSensitive/GRExprEngine.h"
-#include "clang/Analysis/PathSensitive/GRTransferFuncs.h"
+#include "clang/Analysis/PathSensitive/CheckerVisitor.h"
+#include "clang/Analysis/PathSensitive/GRState.h"
+#include "clang/Analysis/LocalCheckers.h"
using namespace clang;
namespace {
-
-class CallInliner : public GRTransferFuncs {
- ASTContext &Ctx;
+class CallInliner : public Checker {
public:
- CallInliner(ASTContext &ctx) : Ctx(ctx) {}
+ static void *getTag() {
+ static int x;
+ return &x;
+ }
- void EvalCall(ExplodedNodeSet& Dst, GRExprEngine& Engine,
- GRStmtNodeBuilder& Builder, CallExpr* CE, SVal L,
- ExplodedNode* Pred);
-
+ virtual bool EvalCallExpr(CheckerContext &C, const CallExpr *CE);
};
+}
+void clang::RegisterCallInliner(GRExprEngine &Eng) {
+ Eng.registerCheck(new CallInliner());
}
-void CallInliner::EvalCall(ExplodedNodeSet& Dst, GRExprEngine& Engine,
- GRStmtNodeBuilder& Builder, CallExpr* CE, SVal L,
- ExplodedNode* Pred) {
- FunctionDecl const *FD = L.getAsFunctionDecl();
+bool CallInliner::EvalCallExpr(CheckerContext &C, const CallExpr *CE) {
+ const GRState *state = C.getState();
+ const Expr *Callee = CE->getCallee();
+ SVal L = state->getSVal(Callee);
+
+ const FunctionDecl *FD = L.getAsFunctionDecl();
if (!FD)
- return; // GRExprEngine is responsible for the autotransition.
+ return false;
+
+ if (!FD->isThisDeclarationADefinition())
+ return false;
// Make a new LocationContext.
- StackFrameContext const *LocCtx =
- Engine.getAnalysisManager().getStackFrame(FD, Pred->getLocationContext(), CE);
+ const StackFrameContext *LocCtx = C.getAnalysisManager().getStackFrame(FD,
+ C.getPredecessor()->getLocationContext(), CE);
CFGBlock const *Entry = &(LocCtx->getCFG()->getEntry());
@@ -54,22 +61,22 @@
// Construct an edge representing the starting location in the function.
BlockEdge Loc(Entry, SuccB, LocCtx);
- GRState const *state = Builder.GetState(Pred);
- state = Engine.getStoreManager().EnterStackFrame(state, LocCtx);
-
- bool isNew;
- ExplodedNode *SuccN = Engine.getGraph().getNode(Loc, state, &isNew);
- SuccN->addPredecessor(Pred, Engine.getGraph());
-
- Builder.Deferred.erase(Pred);
-
+ state = C.getStoreManager().EnterStackFrame(state, LocCtx);
// This is a hack. We really should not use the GRStmtNodeBuilder.
+ bool isNew;
+ GRExprEngine &Eng = C.getEngine();
+ ExplodedNode *Pred = C.getPredecessor();
+ GRStmtNodeBuilder &Builder = C.getNodeBuilder();
+
+ ExplodedNode *SuccN = Eng.getGraph().getNode(Loc, state, &isNew);
+ SuccN->addPredecessor(Pred, Eng.getGraph());
+ C.getNodeBuilder().Deferred.erase(Pred);
+
if (isNew)
Builder.getWorkList()->Enqueue(SuccN);
Builder.HasGeneratedNode = true;
+
+ return true;
}
-
-GRTransferFuncs *clang::CreateCallInliner(ASTContext &ctx) {
- return new CallInliner(ctx);
-}
+
Modified: cfe/trunk/lib/Frontend/AnalysisConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/AnalysisConsumer.cpp?rev=91991&r1=91990&r2=91991&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/AnalysisConsumer.cpp (original)
+++ cfe/trunk/lib/Frontend/AnalysisConsumer.cpp Wed Dec 23 02:56:18 2009
@@ -254,7 +254,7 @@
if (!TranslationUnitActions.empty()) {
// Find the entry function definition (if any).
FunctionDecl *FD = 0;
-
+ // Must specify an entry function.
if (!Opts.AnalyzeSpecificFunction.empty()) {
for (DeclContext::decl_iterator I=TU->decls_begin(), E=TU->decls_end();
I != E; ++I) {
@@ -267,9 +267,11 @@
}
}
- for (Actions::iterator I = TranslationUnitActions.begin(),
- E = TranslationUnitActions.end(); I != E; ++I)
- (*I)(*this, *Mgr, FD);
+ if (FD) {
+ for (Actions::iterator I = TranslationUnitActions.begin(),
+ E = TranslationUnitActions.end(); I != E; ++I)
+ (*I)(*this, *Mgr, FD);
+ }
}
if (!ObjCImplementationActions.empty()) {
@@ -489,8 +491,35 @@
static void ActionInlineCall(AnalysisConsumer &C, AnalysisManager &mgr,
Decl *D) {
+ // FIXME: This is largely copy of ActionGRExprEngine. Needs cleanup.
+ // Display progress.
+ C.DisplayFunction(D);
+
+ GRExprEngine Eng(mgr);
+
+ RegisterCallInliner(Eng);
+
+ if (C.Opts.EnableExperimentalInternalChecks)
+ RegisterExperimentalInternalChecks(Eng);
+
+ RegisterAppleChecks(Eng, *D);
+
+ if (C.Opts.EnableExperimentalChecks)
+ RegisterExperimentalChecks(Eng);
- ActionGRExprEngine(C, mgr, D, CreateCallInliner(mgr.getASTContext()));
+ // Make a fake transfer function. The GRTransferFunc interface will be
+ // removed.
+ Eng.setTransferFunctions(new GRTransferFuncs());
+
+ // Execute the worklist algorithm.
+ Eng.ExecuteWorkList(mgr.getStackFrame(D));
+
+ // Visualize the exploded graph.
+ if (mgr.shouldVisualizeGraphviz())
+ Eng.ViewGraph(mgr.shouldTrimGraph());
+
+ // Display warnings.
+ Eng.getBugReporter().FlushReports();
}
//===----------------------------------------------------------------------===//
More information about the cfe-commits
mailing list