@@ -4319,10 +4319,7 @@ static void emitWriteback(CodeGenFunction &CGF,
43194319
43204320 if (writeback.WritebackExpr ) {
43214321 CGF.EmitIgnoredExpr (writeback.WritebackExpr );
4322-
4323- if (writeback.LifetimeSz )
4324- CGF.EmitLifetimeEnd (writeback.LifetimeSz ,
4325- writeback.Temporary .getBasePointer ());
4322+ CGF.EmitLifetimeEnd (writeback.Temporary .getBasePointer ());
43264323 return ;
43274324 }
43284325
@@ -5282,7 +5279,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
52825279 // If the call returns a temporary with struct return, create a temporary
52835280 // alloca to hold the result, unless one is given to us.
52845281 Address SRetPtr = Address::invalid ();
5285- llvm::Value *UnusedReturnSizePtr = nullptr ;
5282+ bool NeedSRetLifetimeEnd = false ;
52865283 if (RetAI.isIndirect () || RetAI.isInAlloca () || RetAI.isCoerceAndExpand ()) {
52875284 // For virtual function pointer thunks and musttail calls, we must always
52885285 // forward an incoming SRet pointer to the callee, because a local alloca
@@ -5296,11 +5293,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
52965293 SRetPtr = ReturnValue.getAddress ();
52975294 } else {
52985295 SRetPtr = CreateMemTempWithoutCast (RetTy, " tmp" );
5299- if (HaveInsertPoint () && ReturnValue.isUnused ()) {
5300- llvm::TypeSize size =
5301- CGM.getDataLayout ().getTypeAllocSize (ConvertTypeForMem (RetTy));
5302- UnusedReturnSizePtr = EmitLifetimeStart (size, SRetPtr.getBasePointer ());
5303- }
5296+ if (HaveInsertPoint () && ReturnValue.isUnused ())
5297+ NeedSRetLifetimeEnd = EmitLifetimeStart (SRetPtr.getBasePointer ());
53045298 }
53055299 if (IRFunctionArgs.hasSRetArg ()) {
53065300 // A mismatch between the allocated return value's AS and the target's
@@ -5484,15 +5478,10 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
54845478 Val = Builder.CreateFreeze (Val);
54855479 IRCallArgs[FirstIRArg] = Val;
54865480
5487- // Emit lifetime markers for the temporary alloca.
5488- llvm::TypeSize ByvalTempElementSize =
5489- CGM.getDataLayout ().getTypeAllocSize (AI.getElementType ());
5490- llvm::Value *LifetimeSize =
5491- EmitLifetimeStart (ByvalTempElementSize, AI.getPointer ());
5492-
5493- // Add cleanup code to emit the end lifetime marker after the call.
5494- if (LifetimeSize) // In case we disabled lifetime markers.
5495- CallLifetimeEndAfterCall.emplace_back (AI, LifetimeSize);
5481+ // Emit lifetime markers for the temporary alloca and add cleanup code to
5482+ // emit the end lifetime marker after the call.
5483+ if (EmitLifetimeStart (AI.getPointer ()))
5484+ CallLifetimeEndAfterCall.emplace_back (AI);
54965485
54975486 // Generate the copy.
54985487 I->copyInto (*this , AI);
@@ -5653,9 +5642,9 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
56535642 auto unpaddedCoercionType = ArgInfo.getUnpaddedCoerceAndExpandType ();
56545643 auto *unpaddedStruct = dyn_cast<llvm::StructType>(unpaddedCoercionType);
56555644
5656- llvm::Value *tempSize = nullptr ;
56575645 Address addr = Address::invalid ();
56585646 RawAddress AllocaAddr = RawAddress::invalid ();
5647+ bool NeedLifetimeEnd = false ;
56595648 if (I->isAggregate ()) {
56605649 addr = I->hasLValue () ? I->getKnownLValue ().getAddress ()
56615650 : I->getKnownRValue ().getAggregateAddress ();
@@ -5665,7 +5654,6 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
56655654 assert (RV.isScalar ()); // complex should always just be direct
56665655
56675656 llvm::Type *scalarType = RV.getScalarVal ()->getType ();
5668- auto scalarSize = CGM.getDataLayout ().getTypeAllocSize (scalarType);
56695657 auto scalarAlign = CGM.getDataLayout ().getPrefTypeAlign (scalarType);
56705658
56715659 // Materialize to a temporary.
@@ -5674,7 +5662,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
56745662 layout->getAlignment (), scalarAlign)),
56755663 " tmp" ,
56765664 /* ArraySize=*/ nullptr , &AllocaAddr);
5677- tempSize = EmitLifetimeStart (scalarSize, AllocaAddr.getPointer ());
5665+ NeedLifetimeEnd = EmitLifetimeStart (AllocaAddr.getPointer ());
56785666
56795667 Builder.CreateStore (RV.getScalarVal (), addr);
56805668 }
@@ -5699,10 +5687,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
56995687 }
57005688 assert (IRArgPos == FirstIRArg + NumIRArgs);
57015689
5702- if (tempSize) {
5703- EmitLifetimeEnd (tempSize, AllocaAddr.getPointer ());
5704- }
5705-
5690+ if (NeedLifetimeEnd)
5691+ EmitLifetimeEnd (AllocaAddr.getPointer ());
57065692 break ;
57075693 }
57085694
@@ -5871,9 +5857,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
58715857 // can't depend on being inside of an ExprWithCleanups, so we need to manually
58725858 // pop this cleanup later on. Being eager about this is OK, since this
58735859 // temporary is 'invisible' outside of the callee.
5874- if (UnusedReturnSizePtr)
5875- pushFullExprCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker, SRetPtr,
5876- UnusedReturnSizePtr);
5860+ if (NeedSRetLifetimeEnd)
5861+ pushFullExprCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker, SRetPtr);
58775862
58785863 llvm::BasicBlock *InvokeDest = CannotThrow ? nullptr : getInvokeDest ();
58795864
@@ -6007,7 +5992,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
60075992 // insertion point; this allows the rest of IRGen to discard
60085993 // unreachable code.
60095994 if (CI->doesNotReturn ()) {
6010- if (UnusedReturnSizePtr )
5995+ if (NeedSRetLifetimeEnd )
60115996 PopCleanupBlock ();
60125997
60135998 // Strip away the noreturn attribute to better diagnose unreachable UB.
@@ -6122,7 +6107,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
61226107 case ABIArgInfo::InAlloca:
61236108 case ABIArgInfo::Indirect: {
61246109 RValue ret = convertTempToRValue (SRetPtr, RetTy, SourceLocation ());
6125- if (UnusedReturnSizePtr )
6110+ if (NeedSRetLifetimeEnd )
61266111 PopCleanupBlock ();
61276112 return ret;
61286113 }
0 commit comments