summaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExprCXX.cpp
diff options
context:
space:
mode:
authorReid Kleckner <reid@kleckner.net>2013-12-04 19:23:12 +0000
committerReid Kleckner <reid@kleckner.net>2013-12-04 19:23:12 +0000
commitd4abf6549efb81da6ee9053af8bc7918d0a3b192 (patch)
tree1f6992d9eafc8210adaf32c83dee1fb029b71a15 /lib/CodeGen/CGExprCXX.cpp
parent60fc878a5c311cbc77e7cb4146cdf683284a0316 (diff)
downloadclang-d4abf6549efb81da6ee9053af8bc7918d0a3b192.tar.gz
clang-d4abf6549efb81da6ee9053af8bc7918d0a3b192.tar.bz2
clang-d4abf6549efb81da6ee9053af8bc7918d0a3b192.tar.xz
[ms-cxxabi] Construct and destroy call arguments in the correct order
Summary: MSVC destroys arguments in the callee from left to right. Because C++ objects have to be destroyed in the reverse order of construction, Clang has to construct arguments from right to left and destroy arguments from left to right. This patch fixes the ordering by reversing the order of evaluation of all call arguments under the MS C++ ABI. Fixes PR18035. Reviewers: rsmith Differential Revision: http://llvm-reviews.chandlerc.com/D2275 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@196402 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExprCXX.cpp')
-rw-r--r--lib/CodeGen/CGExprCXX.cpp31
1 files changed, 4 insertions, 27 deletions
diff --git a/lib/CodeGen/CGExprCXX.cpp b/lib/CodeGen/CGExprCXX.cpp
index a748620ee7..d4e1e33d73 100644
--- a/lib/CodeGen/CGExprCXX.cpp
+++ b/lib/CodeGen/CGExprCXX.cpp
@@ -1129,35 +1129,12 @@ llvm::Value *CodeGenFunction::EmitCXXNewExpr(const CXXNewExpr *E) {
allocatorArgs.add(RValue::get(allocSize), sizeType);
- // Emit the rest of the arguments.
- // FIXME: Ideally, this should just use EmitCallArgs.
- CXXNewExpr::const_arg_iterator placementArg = E->placement_arg_begin();
-
- // First, use the types from the function type.
// We start at 1 here because the first argument (the allocation size)
// has already been emitted.
- for (unsigned i = 1, e = allocatorType->getNumArgs(); i != e;
- ++i, ++placementArg) {
- QualType argType = allocatorType->getArgType(i);
-
- assert(getContext().hasSameUnqualifiedType(argType.getNonReferenceType(),
- placementArg->getType()) &&
- "type mismatch in call argument!");
-
- EmitCallArg(allocatorArgs, *placementArg, argType);
- }
-
- // Either we've emitted all the call args, or we have a call to a
- // variadic function.
- assert((placementArg == E->placement_arg_end() ||
- allocatorType->isVariadic()) &&
- "Extra arguments to non-variadic function!");
-
- // If we still have any arguments, emit them using the type of the argument.
- for (CXXNewExpr::const_arg_iterator placementArgsEnd = E->placement_arg_end();
- placementArg != placementArgsEnd; ++placementArg) {
- EmitCallArg(allocatorArgs, *placementArg, placementArg->getType());
- }
+ EmitCallArgs(allocatorArgs, allocatorType->isVariadic(),
+ allocatorType->arg_type_begin() + 1,
+ allocatorType->arg_type_end(), E->placement_arg_begin(),
+ E->placement_arg_end());
// Emit the allocation call. If the allocator is a global placement
// operator, just "inline" it directly.