Skip to content

Commit 915b166

Browse files
committed
IRGen: use the accessor conformance on Windows
When building with lazy initialization of the root conformance, we need to ensure that we are invoking the accessor to initialize the conformance record. We would previously generate a direct reference to the conformance, which was uninitialized, resulting in a crash at runtime. The non-windows test changes here are to use/imply static linking for the support modules. This should have no difference on the non-Windows targets, but makes a difference on Windows where this implies that everything will be built into a single module, which permits the non-indirect access to types. Unfortunately, this does somewhat regress the test coverage on Windows as we do not exercise as much of the shared linkage paths which do change some of the code-generation to deal with the moral equivalent of the GOT - the IAT. Special thanks to @slavapestov for the pointer to `isDependentConformance`. This should eliminate the last known issue with cross-module protocol conformances. Fixes: SR-14807
1 parent 6536c5b commit 915b166

8 files changed

+39
-6
lines changed

lib/IRGen/GenProto.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,12 @@ static bool isDependentConformance(
926926
if (!conformance)
927927
return false;
928928

929+
if (IGM.getOptions().LazyInitializeProtocolConformances) {
930+
const auto *MD = rootConformance->getDeclContext()->getParentModule();
931+
if (!(MD == IGM.getSwiftModule() || MD->isStaticLibrary()))
932+
return true;
933+
}
934+
929935
// Check whether we've visited this conformance already. If so,
930936
// optimistically assume it's fine --- we want the maximal fixed point.
931937
if (!visited.insert(conformance).second)

test/IRGen/conformance_resilience.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -emit-module -enable-library-evolution -emit-module-path=%t/resilient_protocol.swiftmodule -module-name=resilient_protocol %S/../Inputs/resilient_protocol.swift
2+
// RUN: %target-swift-frontend -emit-module -static -enable-library-evolution -emit-module-path=%t/resilient_protocol.swiftmodule -module-name=resilient_protocol %S/../Inputs/resilient_protocol.swift
33
// RUN: %target-swift-frontend -I %t -emit-ir -enable-library-evolution %s | %FileCheck %s -DINT=i%target-ptrsize
44
// RUN: %target-swift-frontend -I %t -emit-ir -enable-library-evolution -O %s
55

test/IRGen/lazy-root-conformance.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ extension E : Q {
2121
#endif
2222

2323
// CHECK-DIRECT: @"$s1A1EO1B1QADWP" ={{( dllexport)?}}{{( protected)?}} constant [2 x i8*] [i8* bitcast (%swift.protocol_conformance_descriptor* @"$s1A1EO1B1QADMc" to i8*), i8* bitcast (i8** @"$s1A1EOAA1PAAWP" to i8*)]
24-
// CHECK-INDIRECT: @"$s1A1EO1B1QADWP" ={{( dllexport)?}}{{( protected)?}} constant [2 x i8*] [i8* bitcast (%swift.protocol_conformance_descriptor* @"$s1A1EO1B1QADMc" to i8*), i8* null]
24+
// CHECK-INDIRECT: @"$s1A1EO1B1QADWP" ={{( dllexport)?}}{{( protected)?}} constant [2 x i8*] [i8* bitcast ({{.*}}* @"$s1A1EO1B1QADMc" to i8*), i8* null]
2525

test/IRGen/opaque_result_type_metadata_peephole.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -swift-version 5 -disable-availability-checking -enable-library-evolution -emit-module-path %t/opaque_result_type_metadata_external.swiftmodule %S/Inputs/opaque_result_type_metadata_external.swift
2+
// RUN: %target-swift-frontend -swift-version 5 -disable-availability-checking -static -enable-library-evolution -emit-module-path %t/opaque_result_type_metadata_external.swiftmodule %S/Inputs/opaque_result_type_metadata_external.swift
33
// RUN: %target-swift-frontend -swift-version 5 -disable-availability-checking -emit-ir -I %t %s | %FileCheck %s --check-prefix=CHECK --check-prefix=DEFAULT
44
// RUN: %target-swift-frontend -swift-version 5 -disable-availability-checking -emit-ir -I %t %s -enable-implicit-dynamic | %FileCheck %s --check-prefix=CHECK --check-prefix=IMPLICIT-DYNAMIC
55

test/IRGen/sil_witness_tables.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -emit-module -o %t %S/sil_witness_tables_external_conformance.swift
2+
// RUN: %target-swift-frontend -emit-module -static -o %t %S/sil_witness_tables_external_conformance.swift
33
// RUN: %target-swift-frontend -I %t -primary-file %s -emit-ir | %FileCheck %s
44

55
// REQUIRES: CPU=x86_64

test/IRGen/sil_witness_tables_external_witnesstable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -emit-module %S/Inputs/sil_witness_tables_external_input.swift -o %t/Swift.swiftmodule -parse-stdlib -parse-as-library -module-name Swift -module-link-name swiftCore
2+
// RUN: %target-swift-frontend -emit-module -static %S/Inputs/sil_witness_tables_external_input.swift -o %t/Swift.swiftmodule -parse-stdlib -parse-as-library -module-name Swift -module-link-name swiftCore
33
// RUN: %target-swift-frontend -I %t -primary-file %s -emit-ir | %FileCheck %s
44

55
import Swift
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %target-swift-frontend -S -emit-ir %s -o - | %FileCheck %s
2+
// REQUIRES: OS=windows-msvc
3+
4+
class C {
5+
static func encode(_ c: Encodable) throws {}
6+
}
7+
8+
public protocol P: Codable {}
9+
10+
extension String: P {}
11+
12+
public enum E {
13+
case associated(P)
14+
}
15+
16+
extension E: Encodable {
17+
public func encode(to encoder: Encoder) throws {
18+
switch self {
19+
case .associated(let p):
20+
try p.encode(to: encoder)
21+
}
22+
}
23+
}
24+
25+
try? print(C.encode(E.associated("string")))
26+
27+
// CHECK-NOT: store i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @"$sSS4main1PAAWP", i32 0, i32 0), i8***

test/IRGen/windows-linking.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct Entry {
5656
// through the IAT.
5757

5858
// CHECK-SHARED: @"$s6module1EO4main1QADWP" = hidden constant [2 x i8*] [
59-
// CHECK-SHARED-SAME: i8* bitcast (%swift.protocol_conformance_descriptor* @"$s6module1EO4main1QADMc" to i8*),
59+
// CHECK-SHARED-SAME: i8* bitcast ({ i32, i32, i32, i32, i16, i16, i32, i32 }* @"$s6module1EO4main1QADMc" to i8*),
6060
// CHECK-SHARED-SAME: i8* null
6161
// CHECK-SHARED-SAME: ]
6262

0 commit comments

Comments
 (0)