diff --git a/SwiftCompilerSources/Sources/Optimizer/PassManager/ContextCommon.swift b/SwiftCompilerSources/Sources/Optimizer/PassManager/ContextCommon.swift index 97b79ee4d5a4d..2d131b3ac20e2 100644 --- a/SwiftCompilerSources/Sources/Optimizer/PassManager/ContextCommon.swift +++ b/SwiftCompilerSources/Sources/Optimizer/PassManager/ContextCommon.swift @@ -96,23 +96,26 @@ extension MutatingContext { func inlineFunction(apply: FullApplySite, mandatoryInline: Bool) { // This is only a best-effort attempt to notify the new cloned instructions as changed. // TODO: get a list of cloned instructions from the `inlineFunction` - let instAfterInling: Instruction? + let instBeforeInlining = apply.previous + let instAfterInlining: Instruction? switch apply { case is ApplyInst: - instAfterInling = apply.next + instAfterInlining = apply.next case let beginApply as BeginApplyInst: let next = beginApply.next! - instAfterInling = (next is EndApplyInst ? nil : next) + instAfterInlining = (next is EndApplyInst ? nil : next) case is TryApplyInst: - instAfterInling = apply.parentBlock.next?.instructions.first + instAfterInlining = apply.parentBlock.next?.instructions.first default: - instAfterInling = nil + instAfterInlining = nil } bridgedPassContext.inlineFunction(apply.bridged, mandatoryInline) - if let instAfterInling = instAfterInling { - notifyNewInstructions(from: apply, to: instAfterInling) + if let instBeforeInlining = instBeforeInlining?.next, + let instAfterInlining = instAfterInlining, + !instAfterInlining.isDeleted { + notifyNewInstructions(from: instBeforeInlining, to: instAfterInlining) } } diff --git a/validation-test/SILOptimizer/rdar161433604.swift b/validation-test/SILOptimizer/rdar161433604.swift new file mode 100644 index 0000000000000..26771f3bb1cd1 --- /dev/null +++ b/validation-test/SILOptimizer/rdar161433604.swift @@ -0,0 +1,24 @@ +// RUN: %target-swift-frontend \ +// RUN: -disable-availability-checking \ +// RUN: -target %target-swift-5.9-abi-triple \ +// RUN: -emit-sil -verify \ +// RUN: -enable-experimental-feature LifetimeDependence \ +// RUN: -enable-experimental-feature Embedded \ +// RUN: %s + +// REQUIRES: OS=macosx || OS=linux-gnu +// REQUIRES: swift_feature_Embedded +// REQUIRES: swift_feature_LifetimeDependence + +struct NoEscapeNoCopy: ~Escapable, ~Copyable {} + +protocol Foo { + var bar: NoEscapeNoCopy {get} +} + +public struct Baz: Foo { + var bar: NoEscapeNoCopy { + NoEscapeNoCopy() // expected-error{{lifetime-dependent value escapes its scope}} + // expected-note@-1{{it depends on the lifetime of this parent value}} + } // expected-note{{this use causes the lifetime-dependent value to escape}} +}