Skip to content

Commit f9b50bb

Browse files
authored
Merge pull request #7235 from slavapestov/fix-unowned-other-module
SILGen: Fix crash with access to unowned/weak property in other module
2 parents b15f016 + a073f66 commit f9b50bb

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

lib/SILGen/SILGenLValue.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2066,7 +2066,8 @@ LValue SILGenFunction::emitPropertyLValue(SILLocation loc, ManagedValue base,
20662066

20672067
if (varStorageType.is<ReferenceStorageType>()) {
20682068
auto formalRValueType =
2069-
ivar->getType()->getRValueType()->getReferenceStorageReferent()
2069+
ivar->getDeclContext()->mapTypeIntoContext(ivar->getInterfaceType())
2070+
->getReferenceStorageReferent()
20702071
->getCanonicalType();
20712072
auto typeData =
20722073
getPhysicalStorageTypeData(SGM, ivar, formalRValueType);

test/SILGen/Inputs/weak_other.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
public struct Flags {
2+
public func asBoolean() -> Bool { return true }
3+
}
4+
5+
public protocol Router : class {
6+
7+
}
8+
9+
extension Router {
10+
public var flags: Flags { return Flags() }
11+
}
12+
13+
public protocol Environment : class {
14+
unowned var router: Router { get }
15+
}
16+
17+
open class UI {
18+
open unowned let environment: Environment
19+
20+
init(e: Environment) {
21+
environment = e
22+
}
23+
}

test/SILGen/extensions_multifile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -Xllvm -new-mangling-for-tests -emit-silgen -primary-file %s %S/Inputs/struct_with_initializer.swift -module-name extensions_multifile | tee /tmp/xxx | %FileCheck %s
1+
// RUN: %target-swift-frontend -Xllvm -new-mangling-for-tests -emit-silgen -primary-file %s %S/Inputs/struct_with_initializer.swift -module-name extensions_multifile | %FileCheck %s
22

33
// CHECK-LABEL: sil hidden @_T020extensions_multifile12HasInitValueVACSi1x_tcfC : $@convention(method) (Int, @thin HasInitValue.Type) -> HasInitValue {
44
// CHECK: function_ref @_T020extensions_multifile12HasInitValueV1xSivfi : $@convention(thin) () -> Int
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: rm -rf %t && mkdir %t
2+
// RUN: %target-swift-frontend -emit-module -emit-module-path=%t/weak_other.swiftmodule -module-name=weak_other %S/Inputs/weak_other.swift
3+
// RUN: %target-swift-frontend -Xllvm -new-mangling-for-tests -I %t -emit-silgen %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-runtime
4+
5+
import weak_other
6+
7+
// CHECK-LABEL: sil hidden @_T021weak_multiple_modules11doSomethingSb0A6_other2UIC2ui_tF : $@convention(thin) (@owned UI) -> Bool
8+
func doSomething(ui: UI) -> Bool {
9+
// CHECK: ref_element_addr
10+
// CHECK-objc: load_unowned
11+
// CHECK-native: load [take]
12+
// CHECK-native: strong_retain_unowned
13+
// CHECK: open_existential_ref
14+
// CHECK: witness_method
15+
// CHECK: apply
16+
// CHECK: open_existential_ref
17+
// CHECK: function_ref
18+
// CHECK: apply
19+
// CHECK: return
20+
return ui.environment.router.flags.asBoolean()
21+
}

0 commit comments

Comments
 (0)