[cfe-commits] r86343 - in /cfe/trunk: include/clang/Analysis/Support/SaveAndRestore.h lib/Analysis/LiveVariables.cpp
Ted Kremenek
kremenek at apple.com
Fri Nov 6 21:57:36 PST 2009
Author: kremenek
Date: Fri Nov 6 23:57:35 2009
New Revision: 86343
URL: http://llvm.org/viewvc/llvm-project?rev=86343&view=rev
Log:
Use SaveAndRestore to simplify logic in LiveVariables::runOnAllBlocks(). Patch by Kovarththanan Rajaratnam!
Modified:
cfe/trunk/include/clang/Analysis/Support/SaveAndRestore.h
cfe/trunk/lib/Analysis/LiveVariables.cpp
Modified: cfe/trunk/include/clang/Analysis/Support/SaveAndRestore.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Support/SaveAndRestore.h?rev=86343&r1=86342&r2=86343&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/Support/SaveAndRestore.h (original)
+++ cfe/trunk/include/clang/Analysis/Support/SaveAndRestore.h Fri Nov 6 23:57:35 2009
@@ -22,6 +22,9 @@
template<typename T>
struct SaveAndRestore {
SaveAndRestore(T& x) : X(x), old_value(x) {}
+ SaveAndRestore(T& x, const T &new_value) : X(x), old_value(x) {
+ X = new_value;
+ }
~SaveAndRestore() { X = old_value; }
T get() { return old_value; }
private:
Modified: cfe/trunk/lib/Analysis/LiveVariables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/LiveVariables.cpp?rev=86343&r1=86342&r2=86343&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/LiveVariables.cpp (original)
+++ cfe/trunk/lib/Analysis/LiveVariables.cpp Fri Nov 6 23:57:35 2009
@@ -18,6 +18,7 @@
#include "clang/Analysis/CFG.h"
#include "clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h"
#include "clang/Analysis/FlowSensitive/DataflowSolver.h"
+#include "clang/Analysis/Support/SaveAndRestore.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Compiler.h"
@@ -301,10 +302,9 @@
LiveVariables::ObserverTy* Obs,
bool recordStmtValues) {
Solver S(*this);
- ObserverTy* OldObserver = getAnalysisData().Observer;
- getAnalysisData().Observer = Obs;
+ SaveAndRestore<LiveVariables::ObserverTy*> SRObs(getAnalysisData().Observer,
+ Obs);
S.runOnAllBlocks(cfg, recordStmtValues);
- getAnalysisData().Observer = OldObserver;
}
//===----------------------------------------------------------------------===//
More information about the cfe-commits
mailing list