Skip to content

Commit 6b8f0f4

Browse files
fix Expr memory ownership
1 parent 9f9625e commit 6b8f0f4

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/Interpreter/CppInterOp.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,16 +1072,23 @@ namespace Cpp {
10721072
// Here we synthesize a placeholder expression to be able to use
10731073
// Sema::AddOverloadCandidate. Made up expressions are fine because the
10741074
// interface uses the list size and the expression types.
1075+
struct WrapperExpr : public OpaqueValueExpr {
1076+
WrapperExpr() : OpaqueValueExpr(clang::Stmt::EmptyShell()) {}
1077+
};
1078+
WrapperExpr Exprs[arg_types.size()];
10751079
llvm::SmallVector<Expr*> Args;
10761080
Args.reserve(arg_types.size());
1081+
size_t idx = 0;
10771082
for (auto i : arg_types) {
10781083
QualType Type = QualType::getFromOpaquePtr(i.m_Type);
10791084
ExprValueKind ExprKind = ExprValueKind::VK_PRValue;
10801085
if (Type->isReferenceType())
10811086
ExprKind = ExprValueKind::VK_LValue;
1082-
Args.push_back(new (C)
1083-
OpaqueValueExpr(SourceLocation::getFromRawEncoding(1),
1084-
Type.getNonReferenceType(), ExprKind));
1087+
1088+
new (&Exprs[idx]) OpaqueValueExpr(SourceLocation::getFromRawEncoding(1),
1089+
Type.getNonReferenceType(), ExprKind);
1090+
Args.push_back(&Exprs[idx]);
1091+
++idx;
10851092
}
10861093

10871094
// Create a list of template arguments.

0 commit comments

Comments
 (0)