@@ -1353,11 +1353,6 @@ void CodeGenFunction::EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr) {
13531353}
13541354
13551355void CodeGenFunction::EmitFakeUse (Address Addr) {
1356- // We do not emit a fake use if we want to apply optnone to this function,
1357- // even if we might not apply it anyway due to minsize or similar attributes.
1358- if (!CGM.getCodeGenOpts ().DisableO0ImplyOptNone &&
1359- CGM.getCodeGenOpts ().OptimizationLevel == 0 )
1360- return ;
13611356 auto NL = ApplyDebugLocation::CreateEmpty (*this );
13621357 llvm::Value *V = Builder.CreateLoad (Addr, " fake.use" );
13631358 llvm::CallInst *C = Builder.CreateCall (CGM.getLLVMFakeUseFn (), {V});
@@ -1432,9 +1427,9 @@ static uint64_t maxFakeUseAggregateSize(const ASTContext &C) {
14321427
14331428// Helper function to determine whether a variable's or parameter's lifetime
14341429// should be extended.
1435- static bool extendLifetime (const ASTContext &Context, const Decl *FuncDecl ,
1436- const VarDecl &D,
1437- ImplicitParamDecl *CXXABIThisDecl) {
1430+ static bool shouldExtendLifetime (const ASTContext &Context,
1431+ const Decl *FuncDecl, const VarDecl &D,
1432+ ImplicitParamDecl *CXXABIThisDecl) {
14381433 // When we're not inside a valid function it is unlikely that any
14391434 // lifetime extension is useful.
14401435 if (!FuncDecl)
@@ -1711,13 +1706,14 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
17111706
17121707 // Analogous to lifetime markers, we use a 'cleanup' to emit fake.use
17131708 // calls for local variables. We are exempting volatile variables and
1714- // non-scalars larger than 4 times the size of an unsigned int (32 bytes).
1715- // Larger non-scalars are often allocated in memory and may create unnecessary
1709+ // non-scalars larger than 4 times the size of an unsigned int. Larger
1710+ // non-scalars are often allocated in memory and may create unnecessary
17161711 // overhead.
1717- if (CGM.getCodeGenOpts ().ExtendLifetimes ) {
1718- if (extendLifetime (getContext (), CurCodeDecl, D, CXXABIThisDecl))
1712+ if (CGM.getCodeGenOpts ().getExtendVariableLiveness () ==
1713+ CodeGenOptions::ExtendVariableLivenessKind::All) {
1714+ if (shouldExtendLifetime (getContext (), CurCodeDecl, D, CXXABIThisDecl))
17191715 EHStack.pushCleanup <FakeUse>(NormalFakeUse,
1720- emission.getOriginalAllocatedAddress ());
1716+ emission.getAllocatedAddress ());
17211717 }
17221718
17231719 return emission;
@@ -2785,9 +2781,12 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, ParamValue Arg,
27852781 // Push a FakeUse 'cleanup' object onto the EHStack for the parameter,
27862782 // which may be the 'this' pointer. This causes the emission of a fake.use
27872783 // call with the parameter as argument at the end of the function.
2788- if (CGM.getCodeGenOpts ().ExtendLifetimes ||
2789- (CGM.getCodeGenOpts ().ExtendThisPtr && &D == CXXABIThisDecl)) {
2790- if (extendLifetime (getContext (), CurCodeDecl, D, CXXABIThisDecl))
2784+ if (CGM.getCodeGenOpts ().getExtendVariableLiveness () ==
2785+ CodeGenOptions::ExtendVariableLivenessKind::All ||
2786+ (CGM.getCodeGenOpts ().getExtendVariableLiveness () ==
2787+ CodeGenOptions::ExtendVariableLivenessKind::This &&
2788+ &D == CXXABIThisDecl)) {
2789+ if (shouldExtendLifetime (getContext (), CurCodeDecl, D, CXXABIThisDecl))
27912790 EHStack.pushCleanup <FakeUse>(NormalFakeUse, DeclPtr);
27922791 }
27932792
0 commit comments