[cfe-commits] r97724 - in /cfe/trunk: include/clang/Checker/PathSensitive/Environment.h include/clang/Checker/PathSensitive/GRState.h lib/Checker/GRCoreEngine.cpp lib/Checker/GRExprEngine.cpp lib/Checker/GRState.cpp test/Analysis/inline3.c
Zhongxing Xu
xuzhongxing at gmail.com
Thu Mar 4 01:04:52 PST 2010
Author: zhongxingxu
Date: Thu Mar 4 03:04:52 2010
New Revision: 97724
URL: http://llvm.org/viewvc/llvm-project?rev=97724&view=rev
Log:
When profiling Environment, also profile with AnalysisContext*, bacause
we now may have identical states with different analysis context.
Set the right AnalysisContext in state when entering and leaving a callee.
With both of the above changes, we can pass the test case.
Added:
cfe/trunk/test/Analysis/inline3.c
Modified:
cfe/trunk/include/clang/Checker/PathSensitive/Environment.h
cfe/trunk/include/clang/Checker/PathSensitive/GRState.h
cfe/trunk/lib/Checker/GRCoreEngine.cpp
cfe/trunk/lib/Checker/GRExprEngine.cpp
cfe/trunk/lib/Checker/GRState.cpp
Modified: cfe/trunk/include/clang/Checker/PathSensitive/Environment.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Checker/PathSensitive/Environment.h?rev=97724&r1=97723&r2=97724&view=diff
==============================================================================
--- cfe/trunk/include/clang/Checker/PathSensitive/Environment.h (original)
+++ cfe/trunk/include/clang/Checker/PathSensitive/Environment.h Thu Mar 4 03:04:52 2010
@@ -59,11 +59,13 @@
SVal GetSVal(const Stmt* Ex, ValueManager& ValMgr) const;
AnalysisContext &getAnalysisContext() const { return *ACtx; }
+ void setAnalysisContext(AnalysisContext *ctx) { ACtx = ctx; }
/// Profile - Profile the contents of an Environment object for use
/// in a FoldingSet.
static void Profile(llvm::FoldingSetNodeID& ID, const Environment* E) {
E->ExprBindings.Profile(ID);
+ ID.AddPointer(E->ACtx);
}
/// Profile - Used to profile the contents of this object for inclusion
Modified: cfe/trunk/include/clang/Checker/PathSensitive/GRState.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Checker/PathSensitive/GRState.h?rev=97724&r1=97723&r2=97724&view=diff
==============================================================================
--- cfe/trunk/include/clang/Checker/PathSensitive/GRState.h (original)
+++ cfe/trunk/include/clang/Checker/PathSensitive/GRState.h Thu Mar 4 03:04:52 2010
@@ -115,6 +115,8 @@
return Env.getAnalysisContext();
}
+ const GRState *setAnalysisContext(AnalysisContext *ctx) const;
+
/// getEnvironment - Return the environment associated with this state.
/// The environment is the mapping from expressions to values.
const Environment& getEnvironment() const { return Env; }
Modified: cfe/trunk/lib/Checker/GRCoreEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/GRCoreEngine.cpp?rev=97724&r1=97723&r2=97724&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/GRCoreEngine.cpp (original)
+++ cfe/trunk/lib/Checker/GRCoreEngine.cpp Thu Mar 4 03:04:52 2010
@@ -682,6 +682,7 @@
// Get the callee's location context.
const StackFrameContext *LocCtx
= cast<StackFrameContext>(Pred->getLocationContext());
+ state = state->setAnalysisContext(LocCtx->getParent()->getAnalysisContext());
PostStmt Loc(LocCtx->getCallSite(), LocCtx->getParent());
bool isNew;
Modified: cfe/trunk/lib/Checker/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/GRExprEngine.cpp?rev=97724&r1=97723&r2=97724&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Checker/GRExprEngine.cpp Thu Mar 4 03:04:52 2010
@@ -1309,6 +1309,7 @@
const GRState *state = B.getState();
state = getStoreManager().EnterStackFrame(state, LocCtx);
+ state = state->setAnalysisContext(LocCtx->getAnalysisContext());
B.GenerateNode(state, LocCtx);
}
Modified: cfe/trunk/lib/Checker/GRState.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/GRState.cpp?rev=97724&r1=97723&r2=97724&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/GRState.cpp (original)
+++ cfe/trunk/lib/Checker/GRState.cpp Thu Mar 4 03:04:52 2010
@@ -23,6 +23,12 @@
// FIXME: Move this elsewhere.
ConstraintManager::~ConstraintManager() {}
+const GRState *GRState::setAnalysisContext(AnalysisContext *ctx) const {
+ GRState NewState = *this;
+ NewState.Env.setAnalysisContext(ctx);
+ return StateMgr->getPersistentState(NewState);
+}
+
GRStateManager::~GRStateManager() {
for (std::vector<GRState::Printer*>::iterator I=Printers.begin(),
E=Printers.end(); I!=E; ++I)
Added: cfe/trunk/test/Analysis/inline3.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inline3.c?rev=97724&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/inline3.c (added)
+++ cfe/trunk/test/Analysis/inline3.c Thu Mar 4 03:04:52 2010
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -analyze -inline-call -analyzer-store region -analyze-function f2 -verify %s
+
+
+// Test when entering f1(), we set the right AnalysisContext to Environment.
+// Otherwise, block-level expr '1 && a' would not be block-level.
+int a;
+
+void f1() {
+ if (1 && a)
+ return;
+}
+
+void f2() {
+ f1();
+}
More information about the cfe-commits
mailing list