aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CodeGenFunction.h
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-11-24 21:15:44 +0000
committerDouglas Gregor <dgregor@apple.com>2009-11-24 21:15:44 +0000
commit5656e14d91405417182171a705ed3e3d2d6d7aa3 (patch)
tree33bb9d6fde39a94e88529a19425acfdf06f2d500 /lib/CodeGen/CodeGenFunction.h
parente9cbf15b2ebedebc8bb8e162bb5cf25abd70f578 (diff)
Clean up the AST for while loops and fix several problems with
cleanups for while loops: 1) Make sure that we destroy the condition variable of a while statement each time through the loop for, e.g., while (shared_ptr<WorkInt> p = getWorkItem()) { // ... } 2) Make sure that we always enter a new cleanup scope for the body of the while loop, even when there is no compound expression, e.g., while (blah) RAIIObject raii(blah+1); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89800 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenFunction.h')
-rw-r--r--lib/CodeGen/CodeGenFunction.h21
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h
index a0dd7c08bf..a42fa51265 100644
--- a/lib/CodeGen/CodeGenFunction.h
+++ b/lib/CodeGen/CodeGenFunction.h
@@ -171,13 +171,16 @@ public:
CodeGenFunction& CGF;
size_t CleanupStackDepth;
bool OldDidCallStackSave;
+ bool PerformCleanup;
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) {
+ explicit CleanupScope(CodeGenFunction &CGF)
+ : CGF(CGF), PerformCleanup(true)
+ {
CleanupStackDepth = CGF.CleanupEntries.size();
OldDidCallStackSave = CGF.DidCallStackSave;
}
@@ -185,8 +188,24 @@ public:
/// \brief Exit this cleanup scope, emitting any accumulated
/// cleanups.
~CleanupScope() {
+ if (PerformCleanup) {
+ CGF.DidCallStackSave = OldDidCallStackSave;
+ CGF.EmitCleanupBlocks(CleanupStackDepth);
+ }
+ }
+
+ /// \brief Determine whether this scope requires any cleanups.
+ bool requiresCleanups() const {
+ return CGF.CleanupEntries.size() > CleanupStackDepth;
+ }
+
+ /// \brief Force the emission of cleanups now, instead of waiting
+ /// until this object is destroyed.
+ void ForceCleanup() {
+ assert(PerformCleanup && "Already forced cleanup");
CGF.DidCallStackSave = OldDidCallStackSave;
CGF.EmitCleanupBlocks(CleanupStackDepth);
+ PerformCleanup = false;
}
};