diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-11-24 16:43:22 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-11-24 16:43:22 +0000 |
commit | 965f450d423f9dd8649b60aa0f65ca8ffdb8e4d8 (patch) | |
tree | 6cf422d5fff49f1359712b9ca14de78747c383e6 /clang/lib/CodeGen/CodeGenFunction.h | |
parent | 8e4b3ed386f877f6a77c05b4431412b1bbf184ac (diff) | |
download | bcm5719-llvm-965f450d423f9dd8649b60aa0f65ca8ffdb8e4d8.tar.gz bcm5719-llvm-965f450d423f9dd8649b60aa0f65ca8ffdb8e4d8.zip |
Introduce cleanup scopes for "if" statements in two places:
- Outside the "if", to ensure that we destroy the condition variable
at the end of the "if" statement rather than at the end of the
block containing the "if" statement.
- Inside the "then" and "else" branches, so that we emit then- or
else-local cleanups at the end of the corresponding block when the
block is not a compound statement.
To make adding these new cleanup scopes easier (and since
switch/do/while will all need the same treatment), added the
CleanupScope RAII object to introduce a new cleanup scope and make
sure it gets cleaned up.
llvm-svn: 89773
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.h')
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index dd26428f819..be1a15ed665 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -165,6 +165,31 @@ public: } }; + /// \brief Enters a new scope for capturing cleanups, all of which will be + /// executed once the scope is exited. + class CleanupScope { + CodeGenFunction& CGF; + size_t CleanupStackDepth; + bool OldDidCallStackSave; + + CleanupScope(const CleanupScope &); // DO NOT IMPLEMENT + CleanupScope &operator=(const CleanupScope &); // DO NOT IMPLEMENT + + public: + /// \brief Enter a new cleanup scope. + explicit CleanupScope(CodeGenFunction &CGF) : CGF(CGF) { + CleanupStackDepth = CGF.CleanupEntries.size(); + OldDidCallStackSave = CGF.DidCallStackSave; + } + + /// \brief Exit this cleanup scope, emitting any accumulated + /// cleanups. + ~CleanupScope() { + CGF.DidCallStackSave = OldDidCallStackSave; + CGF.EmitCleanupBlocks(CleanupStackDepth); + } + }; + /// EmitCleanupBlocks - Takes the old cleanup stack size and emits the cleanup /// blocks that have been added. void EmitCleanupBlocks(size_t OldCleanupStackSize); |