When we manage to re-use an expression during tree transformation (=
template instantiation), and that expression might produce a
temporary, invoke MaybeBindToTemporary. Otherwise, we forget to
destroy objects, release objects, etc. Fixes <rdar://problem/10531073>.

llvm-svn: 146301
diff --git a/clang/test/CodeGenCXX/instantiate-temporaries.cpp b/clang/test/CodeGenCXX/instantiate-temporaries.cpp
new file mode 100644
index 0000000..36d1071
--- /dev/null
+++ b/clang/test/CodeGenCXX/instantiate-temporaries.cpp
@@ -0,0 +1,37 @@
+// RUN: %clang-cc1 -triple x86_64-apple-macosx10.7.0 -emit-llvm -o - %s | FileCheck %s
+
+struct X {
+  X();
+  ~X();
+};
+
+struct Y {
+  X get();
+};
+
+struct X2 {
+  X x;
+};
+
+template<typename T>
+void call() {
+  Y().get();
+}
+
+// CHECK: define weak_odr void @_Z4callIiEvv
+// CHECK: call void @_ZN1Y3getEv
+// CHECK-NEXT: call void @_ZN1XD1Ev
+// CHECK-NEXT: ret void
+template void call<int>();  
+
+template<typename T>
+void compound_literal() {
+  (X2){};
+}
+
+// CHECK: define weak_odr void @_Z16compound_literalIiEvv
+// CHECK: call void @_ZN1XC1Ev
+// CHECK-NEXT: call void @_ZN2X2D1Ev
+// CHECK-NEXT: ret void
+template void compound_literal<int>();  
+