diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-11-24 21:15:44 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-11-24 21:15:44 +0000 |
commit | 680f861d74f39bb29ad87346f764da7cc392c5aa (patch) | |
tree | 5b58f11c0249187ebfd9e8ea7081a5050f61015a /clang/lib/CodeGen/CodeGenFunction.h | |
parent | 3c9beab48a6af525b851bfc44b55ddb2b35c5237 (diff) | |
download | bcm5719-llvm-680f861d74f39bb29ad87346f764da7cc392c5aa.tar.gz bcm5719-llvm-680f861d74f39bb29ad87346f764da7cc392c5aa.zip |
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);
llvm-svn: 89800
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.h')
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.h | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index a0dd7c08bf3..a42fa51265e 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/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; } }; |