[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/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp
index 0aadeaa..bf63ac3 100644
--- a/clang/lib/Serialization/ASTWriterStmt.cpp
+++ b/clang/lib/Serialization/ASTWriterStmt.cpp
@@ -1721,8 +1721,15 @@
void ASTStmtWriter::VisitExprWithCleanups(ExprWithCleanups *E) {
VisitExpr(E);
Record.push_back(E->getNumObjects());
- for (unsigned i = 0, e = E->getNumObjects(); i != e; ++i)
- Record.AddDeclRef(E->getObject(i));
+ for (auto &Obj : E->getObjects()) {
+ if (auto *BD = Obj.dyn_cast<BlockDecl *>()) {
+ Record.push_back(serialization::COK_Block);
+ Record.AddDeclRef(BD);
+ } else if (auto *CLE = Obj.dyn_cast<CompoundLiteralExpr *>()) {
+ Record.push_back(serialization::COK_CompoundLiteral);
+ Record.AddStmt(CLE);
+ }
+ }
Record.push_back(E->cleanupsHaveSideEffects());
Record.AddStmt(E->getSubExpr());