diff options
| author | Ted Kremenek <kremenek@apple.com> | 2009-11-07 05:57:35 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2009-11-07 05:57:35 +0000 |
| commit | 975a119f31c293e446c5449915206287b89682b9 (patch) | |
| tree | da92fe333016b01a296eb552e37bbc823736e508 | |
| parent | bc247dce4dc9e28695cadfd722a289f5a0a62257 (diff) | |
| download | bcm5719-llvm-975a119f31c293e446c5449915206287b89682b9.tar.gz bcm5719-llvm-975a119f31c293e446c5449915206287b89682b9.zip | |
Use SaveAndRestore to simplify logic in LiveVariables::runOnAllBlocks(). Patch by Kovarththanan Rajaratnam!
llvm-svn: 86343
| -rw-r--r-- | clang/include/clang/Analysis/Support/SaveAndRestore.h | 3 | ||||
| -rw-r--r-- | clang/lib/Analysis/LiveVariables.cpp | 6 |
2 files changed, 6 insertions, 3 deletions
diff --git a/clang/include/clang/Analysis/Support/SaveAndRestore.h b/clang/include/clang/Analysis/Support/SaveAndRestore.h index 4720c22d990..f720639490d 100644 --- a/clang/include/clang/Analysis/Support/SaveAndRestore.h +++ b/clang/include/clang/Analysis/Support/SaveAndRestore.h @@ -22,6 +22,9 @@ namespace clang { 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: diff --git a/clang/lib/Analysis/LiveVariables.cpp b/clang/lib/Analysis/LiveVariables.cpp index df7e48dfd4a..070481fa146 100644 --- a/clang/lib/Analysis/LiveVariables.cpp +++ b/clang/lib/Analysis/LiveVariables.cpp @@ -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 @@ void LiveVariables::runOnAllBlocks(const CFG& cfg, 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; } //===----------------------------------------------------------------------===// |

