[CodeGen] Emit destructor calls to destruct compound literals
Fix a bug in IRGen where it wasn't destructing compound literals in C
that are ObjC pointer arrays or non-trivial structs. Also diagnose jumps
that enter or exit the lifetime of the compound literals.
rdar://problem/51867864
Differential Revision: https://reviews.llvm.org/D64464
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index 8d9bf17..a0d1fe2 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -556,6 +556,11 @@
Value *VisitMemberExpr(MemberExpr *E);
Value *VisitExtVectorElementExpr(Expr *E) { return EmitLoadOfLValue(E); }
Value *VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
+ // Strictly speaking, we shouldn't be calling EmitLoadOfLValue, which
+ // transitively calls EmitCompoundLiteralLValue, here in C++ since compound
+ // literals aren't l-values in C++. We do so simply because that's the
+ // cleanest way to handle compound literals in C++.
+ // See the discussion here: https://reviews.llvm.org/D64464
return EmitLoadOfLValue(E);
}