|
40 | 40 | #include "llvm/IR/IntrinsicInst.h"
|
41 | 41 | #include "llvm/IR/Intrinsics.h"
|
42 | 42 | #include "llvm/IR/Type.h"
|
| 43 | +#include "llvm/Support/TypeSize.h" |
43 | 44 | #include "llvm/Transforms/Utils/Local.h"
|
44 | 45 | #include <optional>
|
45 | 46 | using namespace clang;
|
@@ -4644,7 +4645,24 @@ void CodeGenFunction::EmitCallArg(CallArgList &args, const Expr *E,
|
4644 | 4645 | return;
|
4645 | 4646 | }
|
4646 | 4647 |
|
4647 |
| - args.add(EmitAnyExprToTemp(E), type); |
| 4648 | + AggValueSlot ArgSlot = AggValueSlot::ignored(); |
| 4649 | + if (hasAggregateEvaluationKind(E->getType())) { |
| 4650 | + Address ArgSlotAlloca = Address::invalid(); |
| 4651 | + ArgSlot = CreateAggTemp(E->getType(), "agg.tmp", &ArgSlotAlloca); |
| 4652 | + |
| 4653 | + // Emit a lifetime start/end for this temporary. If the type has a |
| 4654 | + // destructor, then we need to keep it alive. FIXME: We should still be able |
| 4655 | + // to end the lifetime after the destructor returns. |
| 4656 | + if (!E->getType().isDestructedType()) { |
| 4657 | + llvm::TypeSize size = |
| 4658 | + CGM.getDataLayout().getTypeAllocSize(ConvertTypeForMem(E->getType())); |
| 4659 | + if (llvm::Value *lifetimeSize = |
| 4660 | + EmitLifetimeStart(size, ArgSlotAlloca.getPointer())) |
| 4661 | + args.addLifetimeCleanup({ArgSlotAlloca.getPointer(), lifetimeSize}); |
| 4662 | + } |
| 4663 | + } |
| 4664 | + |
| 4665 | + args.add(EmitAnyExpr(E, ArgSlot), type); |
4648 | 4666 | }
|
4649 | 4667 |
|
4650 | 4668 | QualType CodeGenFunction::getVarArgType(const Expr *Arg) {
|
@@ -5813,6 +5831,9 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
|
5813 | 5831 | for (CallLifetimeEnd &LifetimeEnd : CallLifetimeEndAfterCall)
|
5814 | 5832 | LifetimeEnd.Emit(*this, /*Flags=*/{});
|
5815 | 5833 |
|
| 5834 | + for (const CallArgList::EndLifetimeInfo < : CallArgs.getLifetimeCleanups()) |
| 5835 | + EmitLifetimeEnd(LT.Size, LT.Addr); |
| 5836 | + |
5816 | 5837 | if (!ReturnValue.isExternallyDestructed() &&
|
5817 | 5838 | RetTy.isDestructedType() == QualType::DK_nontrivial_c_struct)
|
5818 | 5839 | pushDestroy(QualType::DK_nontrivial_c_struct, Ret.getAggregateAddress(),
|
|
0 commit comments