Skip to content

Commit 833a453

Browse files
authored
Merge pull request swiftlang#37301 from hborla/wrapped-parameter-miscompile
[SILGen] Fix a miscompile when emitting the application of a wrapped parameter
2 parents c9eac22 + 0999dea commit 833a453

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/SILGen/SILGenExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5253,7 +5253,7 @@ RValue RValueEmitter::visitPropertyWrapperValuePlaceholderExpr(
52535253
RValue RValueEmitter::visitAppliedPropertyWrapperExpr(
52545254
AppliedPropertyWrapperExpr *E, SGFContext C) {
52555255
auto *param = const_cast<ParamDecl *>(E->getParamDecl());
5256-
auto argument = visit(E->getValue(), C);
5256+
auto argument = visit(E->getValue());
52575257
SILDeclRef::Kind initKind;
52585258
switch (E->getValueKind()) {
52595259
case swift::AppliedPropertyWrapperExpr::ValueKind::WrappedValue:

test/SILGen/property_wrapper_parameter.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// RUN: %target-swift-emit-silgen %s | %FileCheck %s
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -o %t -enable-library-evolution %S/Inputs/def_structA.swift
3+
// RUN: %target-swift-emit-silgen %s -I %t | %FileCheck %s
4+
import def_structA
25

36
public struct Projection<T> {
47
public var wrappedValue: T
@@ -283,3 +286,18 @@ func testNonmutatingSetterSynthesis(@NonmutatingSetter value: Int) {
283286
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter30testNonmutatingSetterSynthesis5valueyAA0eF0VySiG_tFSiAFcfu_SiAFcfU_ACL_Sivs : $@convention(thin) (Int, NonmutatingSetter<Int>) -> ()
284287
// CHECK: function_ref @$s26property_wrapper_parameter17NonmutatingSetterV12wrappedValuexvs : $@convention(method) <τ_0_0> (@in τ_0_0, NonmutatingSetter<τ_0_0>) -> ()
285288
}
289+
290+
// CHECK-LABEL: sil hidden [ossa] @$s26property_wrapper_parameter38testImplicitWrapperWithResilientStructyyF : $@convention(thin) () -> ()
291+
func testImplicitWrapperWithResilientStruct() {
292+
let _: (ProjectionWrapper<A>) -> Void = { $value in }
293+
294+
// implicit closure #1 in testImplicitWrapperWithResilientStruct()
295+
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter38testImplicitWrapperWithResilientStructyyFyAA010ProjectionF0Vy11def_structA1AVGcfu_ : $@convention(thin) (@in_guaranteed ProjectionWrapper<A>) -> ()
296+
// CHECK: [[P:%.*]] = alloc_stack $ProjectionWrapper<A>
297+
// CHECK: copy_addr %0 to [initialization] [[P]]
298+
// CHECK: [[I:%.*]] = function_ref @$s26property_wrapper_parameter38testImplicitWrapperWithResilientStructyyFyAA010ProjectionF0Vy11def_structA1AVGcfu_yAHcfU_6$valueL_AHvpfW : $@convention(thin) (@in ProjectionWrapper<A>) -> @out ProjectionWrapper<A>
299+
// CHECK: apply [[I]]({{.*}}, [[P]]) : $@convention(thin) (@in ProjectionWrapper<A>) -> @out ProjectionWrapper<A>
300+
301+
// property wrapper init from projected value of $value #1 in closure #1 in implicit closure #1 in testImplicitWrapperWithResilientStruct()
302+
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter38testImplicitWrapperWithResilientStructyyFyAA010ProjectionF0Vy11def_structA1AVGcfu_yAHcfU_6$valueL_AHvpfW : $@convention(thin) (@in ProjectionWrapper<A>) -> @out ProjectionWrapper<A>
303+
}

0 commit comments

Comments
 (0)