Skip to content

[5.5][SILGen] Fix a miscompile when emitting the application of a wrapped parameter #37323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/SILGen/SILGenExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5258,7 +5258,7 @@ RValue RValueEmitter::visitPropertyWrapperValuePlaceholderExpr(
RValue RValueEmitter::visitAppliedPropertyWrapperExpr(
AppliedPropertyWrapperExpr *E, SGFContext C) {
auto *param = const_cast<ParamDecl *>(E->getParamDecl());
auto argument = visit(E->getValue(), C);
auto argument = visit(E->getValue());
SILDeclRef::Kind initKind;
switch (E->getValueKind()) {
case swift::AppliedPropertyWrapperExpr::ValueKind::WrappedValue:
Expand Down
20 changes: 19 additions & 1 deletion test/SILGen/property_wrapper_parameter.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// RUN: %target-swift-emit-silgen %s | %FileCheck %s
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -o %t -enable-library-evolution %S/Inputs/def_structA.swift
// RUN: %target-swift-emit-silgen %s -I %t | %FileCheck %s
import def_structA

public struct Projection<T> {
public var wrappedValue: T
Expand Down Expand Up @@ -283,3 +286,18 @@ func testNonmutatingSetterSynthesis(@NonmutatingSetter value: Int) {
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter30testNonmutatingSetterSynthesis5valueyAA0eF0VySiG_tFSiAFcfu_SiAFcfU_ACL_Sivs : $@convention(thin) (Int, NonmutatingSetter<Int>) -> ()
// CHECK: function_ref @$s26property_wrapper_parameter17NonmutatingSetterV12wrappedValuexvs : $@convention(method) <τ_0_0> (@in τ_0_0, NonmutatingSetter<τ_0_0>) -> ()
}

// CHECK-LABEL: sil hidden [ossa] @$s26property_wrapper_parameter38testImplicitWrapperWithResilientStructyyF : $@convention(thin) () -> ()
func testImplicitWrapperWithResilientStruct() {
let _: (ProjectionWrapper<A>) -> Void = { $value in }

// implicit closure #1 in testImplicitWrapperWithResilientStruct()
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter38testImplicitWrapperWithResilientStructyyFyAA010ProjectionF0Vy11def_structA1AVGcfu_ : $@convention(thin) (@in_guaranteed ProjectionWrapper<A>) -> ()
// CHECK: [[P:%.*]] = alloc_stack $ProjectionWrapper<A>
// CHECK: copy_addr %0 to [initialization] [[P]]
// CHECK: [[I:%.*]] = function_ref @$s26property_wrapper_parameter38testImplicitWrapperWithResilientStructyyFyAA010ProjectionF0Vy11def_structA1AVGcfu_yAHcfU_6$valueL_AHvpfW : $@convention(thin) (@in ProjectionWrapper<A>) -> @out ProjectionWrapper<A>
// CHECK: apply [[I]]({{.*}}, [[P]]) : $@convention(thin) (@in ProjectionWrapper<A>) -> @out ProjectionWrapper<A>

// property wrapper init from projected value of $value #1 in closure #1 in implicit closure #1 in testImplicitWrapperWithResilientStruct()
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter38testImplicitWrapperWithResilientStructyyFyAA010ProjectionF0Vy11def_structA1AVGcfu_yAHcfU_6$valueL_AHvpfW : $@convention(thin) (@in ProjectionWrapper<A>) -> @out ProjectionWrapper<A>
}