diff options
author | John McCall <rjmccall@apple.com> | 2015-09-29 23:55:17 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2015-09-29 23:55:17 +0000 |
commit | 53dcf94d0593a79b661ae8bb85a9155181b1fc41 (patch) | |
tree | ed22c2226ce719084bebf038ad0c6c995b6013b3 /clang/lib | |
parent | c1db67e218ae22ab626ba75a5f6329786ca84c63 (diff) | |
download | bcm5719-llvm-53dcf94d0593a79b661ae8bb85a9155181b1fc41.tar.gz bcm5719-llvm-53dcf94d0593a79b661ae8bb85a9155181b1fc41.zip |
Don't crash when a reserved global placement operator new is paired
with a non-reserved operator delete in a new-expression.
llvm-svn: 248862
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/CodeGen/CGExprCXX.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp index 7e0a6abc23b..599dc9a8dbc 100644 --- a/clang/lib/CodeGen/CGExprCXX.cpp +++ b/clang/lib/CodeGen/CGExprCXX.cpp @@ -1289,9 +1289,11 @@ llvm::Value *CodeGenFunction::EmitCXXNewExpr(const CXXNewExpr *E) { Address allocation = Address::invalid(); CallArgList allocatorArgs; if (allocator->isReservedGlobalPlacementOperator()) { + assert(E->getNumPlacementArgs() == 1); + const Expr *arg = *E->placement_arguments().begin(); + AlignmentSource alignSource; - allocation = EmitPointerWithAlignment(*E->placement_arguments().begin(), - &alignSource); + allocation = EmitPointerWithAlignment(arg, &alignSource); // The pointer expression will, in many cases, be an opaque void*. // In these cases, discard the computed alignment and use the @@ -1301,6 +1303,14 @@ llvm::Value *CodeGenFunction::EmitCXXNewExpr(const CXXNewExpr *E) { getContext().getTypeAlignInChars(allocType)); } + // Set up allocatorArgs for the call to operator delete if it's not + // the reserved global operator. + if (E->getOperatorDelete() && + !E->getOperatorDelete()->isReservedGlobalPlacementOperator()) { + allocatorArgs.add(RValue::get(allocSize), getContext().getSizeType()); + allocatorArgs.add(RValue::get(allocation.getPointer()), arg->getType()); + } + } else { const FunctionProtoType *allocatorType = allocator->getType()->castAs<FunctionProtoType>(); |