[cfe-commits] r50221 - in /cfe/trunk: include/clang/Analysis/PathSensitive/GRExprEngine.h include/clang/Analysis/PathSensitive/ValueState.h lib/Analysis/GRExprEngine.cpp lib/Analysis/ValueState.cpp
Ted Kremenek
kremenek at apple.com
Thu Apr 24 11:31:42 PDT 2008
Author: kremenek
Date: Thu Apr 24 13:31:42 2008
New Revision: 50221
URL: http://llvm.org/viewvc/llvm-project?rev=50221&view=rev
Log:
Added initial boilerplate in GRExprEngine to allow checker-specific transfer
function logic to act when symbols become dead.
Modified:
cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h
cfe/trunk/include/clang/Analysis/PathSensitive/ValueState.h
cfe/trunk/lib/Analysis/GRExprEngine.cpp
cfe/trunk/lib/Analysis/ValueState.cpp
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h?rev=50221&r1=50220&r2=50221&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h Thu Apr 24 13:31:42 2008
@@ -53,6 +53,10 @@
/// Expr* in the CFG. Used to prune out dead state.
LiveVariables Liveness;
+ /// DeadSymbols - A scratch set used to record the set of symbols that
+ /// were just marked dead by a call to ValueStateManager::RemoveDeadBindings.
+ ValueStateManager::DeadSymbolsTy DeadSymbols;
+
/// Builder - The current GRStmtNodeBuilder which is used when building the
/// nodes for a given statement.
StmtNodeBuilder* Builder;
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/ValueState.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/ValueState.h?rev=50221&r1=50220&r2=50221&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/ValueState.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/ValueState.h Thu Apr 24 13:31:42 2008
@@ -30,6 +30,7 @@
#include "llvm/ADT/ImmutableMap.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/DenseSet.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Streams.h"
@@ -222,8 +223,11 @@
BasicValueFactory& getBasicValueFactory() { return BasicVals; }
SymbolManager& getSymbolManager() { return SymMgr; }
+ typedef llvm::DenseSet<SymbolID> DeadSymbolsTy;
+
ValueState* RemoveDeadBindings(ValueState* St, Stmt* Loc,
- const LiveVariables& Liveness);
+ const LiveVariables& Liveness,
+ DeadSymbolsTy& DeadSymbols);
ValueState* RemoveSubExprBindings(ValueState* St) {
ValueState NewSt = *St;
Modified: cfe/trunk/lib/Analysis/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRExprEngine.cpp?rev=50221&r1=50220&r2=50221&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Thu Apr 24 13:31:42 2008
@@ -188,13 +188,34 @@
// Create the cleaned state.
CleanedState = StateMgr.RemoveDeadBindings(StmtEntryNode->getState(),
- CurrentStmt, Liveness);
+ CurrentStmt, Liveness,
+ DeadSymbols);
- Builder->SetCleanedState(CleanedState);
+ // Process any special transfer function for dead symbols.
- // Visit the statement.
+ NodeSet Tmp;
- Visit(S, StmtEntryNode, Dst);
+ if (DeadSymbols.empty())
+ Tmp.Add(StmtEntryNode);
+ else {
+ SaveAndRestore<bool> OldSink(Builder->BuildSinks);
+/*
+ FIXME: Will hook this up next.
+
+ TF->EvalDeadSymbols(Tmp, *this, *Builder, StmtEntryNode->getLocation(), Pred,
+ CleanedState, DeadSymbols);
+*/
+ if (!Builder->BuildSinks && Tmp.empty() && !Builder->HasGeneratedNode)
+ Tmp.Add(StmtEntryNode);
+ }
+
+ for (NodeSet::iterator I=Tmp.begin(), E=Tmp.end(); I!=E; ++I) {
+ // Set the cleaned state.
+ Builder->SetCleanedState(*I == StmtEntryNode ? CleanedState : (*I)->getState());
+
+ // Visit the statement.
+ Visit(S, StmtEntryNode, Dst);
+ }
// If no nodes were generated, generate a new node that has all the
// dead mappings removed.
Modified: cfe/trunk/lib/Analysis/ValueState.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ValueState.cpp?rev=50221&r1=50220&r2=50221&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/ValueState.cpp (original)
+++ cfe/trunk/lib/Analysis/ValueState.cpp Thu Apr 24 13:31:42 2008
@@ -32,7 +32,8 @@
ValueState*
ValueStateManager::RemoveDeadBindings(ValueState* St, Stmt* Loc,
- const LiveVariables& Liveness) {
+ const LiveVariables& Liveness,
+ DeadSymbolsTy& DeadSymbols) {
// This code essentially performs a "mark-and-sweep" of the VariableBindings.
// The roots are any Block-level exprs and Decls that our liveness algorithm
@@ -133,13 +134,28 @@
NewSt.VarBindings = Remove(NewSt, I.getKey());
// Remove dead symbols.
- for (ValueState::ce_iterator I = St->ce_begin(), E=St->ce_end(); I!=E; ++I)
- if (!MarkedSymbols.count(I.getKey()))
- NewSt.ConstEq = CEFactory.Remove(NewSt.ConstEq, I.getKey());
-
- for (ValueState::cne_iterator I = St->cne_begin(), E=St->cne_end(); I!=E; ++I)
- if (!MarkedSymbols.count(I.getKey()))
- NewSt.ConstNotEq = CNEFactory.Remove(NewSt.ConstNotEq, I.getKey());
+
+ DeadSymbols.clear();
+
+ for (ValueState::ce_iterator I = St->ce_begin(), E=St->ce_end(); I!=E; ++I) {
+
+ SymbolID sym = I.getKey();
+
+ if (!MarkedSymbols.count(sym)) {
+ DeadSymbols.insert(sym);
+ NewSt.ConstEq = CEFactory.Remove(NewSt.ConstEq, sym);
+ }
+ }
+
+ for (ValueState::cne_iterator I = St->cne_begin(), E=St->cne_end(); I!=E;++I){
+
+ SymbolID sym = I.getKey();
+
+ if (!MarkedSymbols.count(sym)) {
+ DeadSymbols.insert(sym);
+ NewSt.ConstNotEq = CNEFactory.Remove(NewSt.ConstNotEq, sym);
+ }
+ }
return getPersistentState(NewSt);
}
More information about the cfe-commits
mailing list