Introduce a CXXTemporariesCleanupScope RAII object and use it to cleanup the temporaries code.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99865 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h
index 31ab101..373c46b 100644
--- a/lib/CodeGen/CodeGenFunction.h
+++ b/lib/CodeGen/CodeGenFunction.h
@@ -254,6 +254,27 @@
     }
   };
 
+  /// CXXTemporariesCleanupScope - Enters a new scope for catching live
+  /// temporaries, all of which will be popped once the scope is exited.
+  class CXXTemporariesCleanupScope {
+    CodeGenFunction &CGF;
+    size_t NumLiveTemporaries;
+    
+    // DO NOT IMPLEMENT
+    CXXTemporariesCleanupScope(const CXXTemporariesCleanupScope &); 
+    CXXTemporariesCleanupScope &operator=(const CXXTemporariesCleanupScope &);
+    
+  public:
+    explicit CXXTemporariesCleanupScope(CodeGenFunction &CGF)
+      : CGF(CGF), NumLiveTemporaries(CGF.LiveTemporaries.size()) { }
+    
+    ~CXXTemporariesCleanupScope() {
+      while (CGF.LiveTemporaries.size() > NumLiveTemporaries)
+        CGF.PopCXXTemporary();
+    }
+  };
+
+
   /// EmitCleanupBlocks - Takes the old cleanup stack size and emits the cleanup
   /// blocks that have been added.
   void EmitCleanupBlocks(size_t OldCleanupStackSize);