@@ -4319,10 +4319,7 @@ static void emitWriteback(CodeGenFunction &CGF,
4319
4319
4320
4320
if (writeback.WritebackExpr ) {
4321
4321
CGF.EmitIgnoredExpr (writeback.WritebackExpr );
4322
-
4323
- if (writeback.LifetimeSz )
4324
- CGF.EmitLifetimeEnd (writeback.LifetimeSz ,
4325
- writeback.Temporary .getBasePointer ());
4322
+ CGF.EmitLifetimeEnd (writeback.Temporary .getBasePointer ());
4326
4323
return ;
4327
4324
}
4328
4325
@@ -5282,7 +5279,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
5282
5279
// If the call returns a temporary with struct return, create a temporary
5283
5280
// alloca to hold the result, unless one is given to us.
5284
5281
Address SRetPtr = Address::invalid ();
5285
- llvm::Value *UnusedReturnSizePtr = nullptr ;
5282
+ bool NeedSRetLifetimeEnd = false ;
5286
5283
if (RetAI.isIndirect () || RetAI.isInAlloca () || RetAI.isCoerceAndExpand ()) {
5287
5284
// For virtual function pointer thunks and musttail calls, we must always
5288
5285
// forward an incoming SRet pointer to the callee, because a local alloca
@@ -5296,11 +5293,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
5296
5293
SRetPtr = ReturnValue.getAddress ();
5297
5294
} else {
5298
5295
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 ());
5304
5298
}
5305
5299
if (IRFunctionArgs.hasSRetArg ()) {
5306
5300
// A mismatch between the allocated return value's AS and the target's
@@ -5484,15 +5478,10 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
5484
5478
Val = Builder.CreateFreeze (Val);
5485
5479
IRCallArgs[FirstIRArg] = Val;
5486
5480
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);
5496
5485
5497
5486
// Generate the copy.
5498
5487
I->copyInto (*this , AI);
@@ -5653,9 +5642,9 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
5653
5642
auto unpaddedCoercionType = ArgInfo.getUnpaddedCoerceAndExpandType ();
5654
5643
auto *unpaddedStruct = dyn_cast<llvm::StructType>(unpaddedCoercionType);
5655
5644
5656
- llvm::Value *tempSize = nullptr ;
5657
5645
Address addr = Address::invalid ();
5658
5646
RawAddress AllocaAddr = RawAddress::invalid ();
5647
+ bool NeedLifetimeEnd = false ;
5659
5648
if (I->isAggregate ()) {
5660
5649
addr = I->hasLValue () ? I->getKnownLValue ().getAddress ()
5661
5650
: I->getKnownRValue ().getAggregateAddress ();
@@ -5665,7 +5654,6 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
5665
5654
assert (RV.isScalar ()); // complex should always just be direct
5666
5655
5667
5656
llvm::Type *scalarType = RV.getScalarVal ()->getType ();
5668
- auto scalarSize = CGM.getDataLayout ().getTypeAllocSize (scalarType);
5669
5657
auto scalarAlign = CGM.getDataLayout ().getPrefTypeAlign (scalarType);
5670
5658
5671
5659
// Materialize to a temporary.
@@ -5674,7 +5662,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
5674
5662
layout->getAlignment (), scalarAlign)),
5675
5663
" tmp" ,
5676
5664
/* ArraySize=*/ nullptr , &AllocaAddr);
5677
- tempSize = EmitLifetimeStart (scalarSize, AllocaAddr.getPointer ());
5665
+ NeedLifetimeEnd = EmitLifetimeStart (AllocaAddr.getPointer ());
5678
5666
5679
5667
Builder.CreateStore (RV.getScalarVal (), addr);
5680
5668
}
@@ -5699,10 +5687,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
5699
5687
}
5700
5688
assert (IRArgPos == FirstIRArg + NumIRArgs);
5701
5689
5702
- if (tempSize) {
5703
- EmitLifetimeEnd (tempSize, AllocaAddr.getPointer ());
5704
- }
5705
-
5690
+ if (NeedLifetimeEnd)
5691
+ EmitLifetimeEnd (AllocaAddr.getPointer ());
5706
5692
break ;
5707
5693
}
5708
5694
@@ -5871,9 +5857,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
5871
5857
// can't depend on being inside of an ExprWithCleanups, so we need to manually
5872
5858
// pop this cleanup later on. Being eager about this is OK, since this
5873
5859
// 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);
5877
5862
5878
5863
llvm::BasicBlock *InvokeDest = CannotThrow ? nullptr : getInvokeDest ();
5879
5864
@@ -6007,7 +5992,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
6007
5992
// insertion point; this allows the rest of IRGen to discard
6008
5993
// unreachable code.
6009
5994
if (CI->doesNotReturn ()) {
6010
- if (UnusedReturnSizePtr )
5995
+ if (NeedSRetLifetimeEnd )
6011
5996
PopCleanupBlock ();
6012
5997
6013
5998
// Strip away the noreturn attribute to better diagnose unreachable UB.
@@ -6122,7 +6107,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
6122
6107
case ABIArgInfo::InAlloca:
6123
6108
case ABIArgInfo::Indirect: {
6124
6109
RValue ret = convertTempToRValue (SRetPtr, RetTy, SourceLocation ());
6125
- if (UnusedReturnSizePtr )
6110
+ if (NeedSRetLifetimeEnd )
6126
6111
PopCleanupBlock ();
6127
6112
return ret;
6128
6113
}
0 commit comments