Skip to content

Commit 29a73bc

Browse files
committed
[IRGen] Fix encoding of the root generic parameter in an associated type reference.
The root generic parameter of an associated type reference in a generic requirement is not shifted by one.
1 parent 705cfa4 commit 29a73bc

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ llvm::Constant *IRGenModule::getAddrOfAssociatedTypeGenericParamRef(
901901
// Otherwise, build the reference path.
902902
ConstantInitBuilder builder(*this);
903903
auto B = builder.beginStruct();
904-
B.addInt32(ordinal << 1);
904+
B.addInt32(ordinal);
905905

906906
for (auto *assocType : reversed(assocTypePath)) {
907907
auto proto = getConstantReferenceForProtocolDescriptor(

test/IRGen/generic_types.swift

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,6 @@
9393
// CHECK-SAME: i32 {{3|2}},
9494
// CHECK-SAME: }
9595

96-
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} internal %swift.type* @"$s13generic_types1ACMi"(%swift.type_descriptor*, i8**, i8*) {{.*}} {
97-
// CHECK: [[T0:%.*]] = bitcast i8** %1 to %swift.type**
98-
// CHECK: %T = load %swift.type*, %swift.type** [[T0]],
99-
// CHECK: [[METADATA:%.*]] = call %swift.type* @swift_allocateGenericClassMetadata(%swift.type_descriptor* %0, i8** %1, i8* %2)
100-
// CHECK-NEXT: ret %swift.type* [[METADATA]]
101-
// CHECK: }
102-
103-
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} internal %swift.type* @"$s13generic_types1BCMi"(%swift.type_descriptor*, i8**, i8*) {{.*}} {
104-
// CHECK: [[T0:%.*]] = bitcast i8** %1 to %swift.type**
105-
// CHECK: %T = load %swift.type*, %swift.type** [[T0]],
106-
// CHECK: [[METADATA:%.*]] = call %swift.type* @swift_allocateGenericClassMetadata(%swift.type_descriptor* %0, i8** %1, i8* %2)
107-
// CHECK-NEXT: ret %swift.type* [[METADATA]]
108-
// CHECK: }
109-
11096
class A<T> {
11197
var x = 0
11298

@@ -149,3 +135,38 @@ func testFixed() {
149135
var a = F(value: ClassA()).value
150136
var b = F(value: ClassB()).value
151137
}
138+
139+
// Checking generic requirement encoding
140+
protocol P1 { }
141+
protocol P2 {
142+
associatedtype A
143+
}
144+
145+
struct X1: P1 { }
146+
struct X2: P2 {
147+
typealias A = X1
148+
}
149+
150+
// Check for correct root generic parameters in the generic requirements of X3.
151+
// CHECK-LABEL: @"$sq_1A13generic_types2P2P_MXA" = linkonce_odr hidden constant
152+
153+
// Root: generic parameter 1
154+
// CHECK-SAME: i32 1
155+
156+
// Protocol P2
157+
// CHECK-SAME: $s13generic_types2P2Mp
158+
struct X3<T, U> where U: P2, U.A: P1 { }
159+
160+
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} internal %swift.type* @"$s13generic_types1ACMi"(%swift.type_descriptor*, i8**, i8*) {{.*}} {
161+
// CHECK: [[T0:%.*]] = bitcast i8** %1 to %swift.type**
162+
// CHECK: %T = load %swift.type*, %swift.type** [[T0]],
163+
// CHECK: [[METADATA:%.*]] = call %swift.type* @swift_allocateGenericClassMetadata(%swift.type_descriptor* %0, i8** %1, i8* %2)
164+
// CHECK-NEXT: ret %swift.type* [[METADATA]]
165+
// CHECK: }
166+
167+
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} internal %swift.type* @"$s13generic_types1BCMi"(%swift.type_descriptor*, i8**, i8*) {{.*}} {
168+
// CHECK: [[T0:%.*]] = bitcast i8** %1 to %swift.type**
169+
// CHECK: %T = load %swift.type*, %swift.type** [[T0]],
170+
// CHECK: [[METADATA:%.*]] = call %swift.type* @swift_allocateGenericClassMetadata(%swift.type_descriptor* %0, i8** %1, i8* %2)
171+
// CHECK-NEXT: ret %swift.type* [[METADATA]]
172+
// CHECK: }

0 commit comments

Comments
 (0)