Skip to content

Commit 281ad7e

Browse files
authored
Merge pull request #19958 from DougGregor/demangle-to-metadata-round-fixes-N
[IRGen] Fix issues impacting the mangled name <-> roundtrip verification
2 parents c8dd802 + 29a73bc commit 281ad7e

File tree

3 files changed

+52
-28
lines changed

3 files changed

+52
-28
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ void IRGenModule::emitRuntimeRegistration() {
613613
if (DebugInfo && !Context.LangOpts.DebuggerSupport)
614614
DebugInfo->emitArtificialFunction(RegIGF, RegistrationFunction);
615615

616-
// Register ObjC protocols, classes, and extensions we added.
616+
// Register ObjC protocols we added.
617617
if (ObjCInterop) {
618618
if (!ObjCProtocols.empty()) {
619619
// We need to initialize ObjC protocols in inheritance order, parents
@@ -649,14 +649,6 @@ void IRGenModule::emitRuntimeRegistration() {
649649
.visitMembers(proto);
650650
}
651651
}
652-
653-
for (llvm::WeakTrackingVH &ObjCClass : ObjCClasses) {
654-
RegIGF.Builder.CreateCall(getInstantiateObjCClassFn(), {ObjCClass});
655-
}
656-
657-
for (ExtensionDecl *ext : ObjCCategoryDecls) {
658-
CategoryInitializerVisitor(RegIGF, ext).visitMembers(ext);
659-
}
660652
}
661653

662654
// Register Swift protocols if we added any.
@@ -716,6 +708,17 @@ void IRGenModule::emitRuntimeRegistration() {
716708
RegIGF.Builder.CreateCall(getRegisterTypeMetadataRecordsFn(), {begin, end});
717709
}
718710

711+
// Register Objective-C classes and extensions we added.
712+
if (ObjCInterop) {
713+
for (llvm::WeakTrackingVH &ObjCClass : ObjCClasses) {
714+
RegIGF.Builder.CreateCall(getInstantiateObjCClassFn(), {ObjCClass});
715+
}
716+
717+
for (ExtensionDecl *ext : ObjCCategoryDecls) {
718+
CategoryInitializerVisitor(RegIGF, ext).visitMembers(ext);
719+
}
720+
}
721+
719722
if (!FieldDescriptors.empty()) {
720723
emitFieldDescriptors();
721724
}
@@ -898,7 +901,7 @@ llvm::Constant *IRGenModule::getAddrOfAssociatedTypeGenericParamRef(
898901
// Otherwise, build the reference path.
899902
ConstantInitBuilder builder(*this);
900903
auto B = builder.beginStruct();
901-
B.addInt32(ordinal << 1);
904+
B.addInt32(ordinal);
902905

903906
for (auto *assocType : reversed(assocTypePath)) {
904907
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: }

test/Prototypes/CollectionTransformers.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
12-
// RUN: %target-run-stdlib-swift-swift3
12+
// RUN: %target-run-stdlib-swift
1313
// REQUIRES: executable_test
1414

1515
// FIXME: This test runs very slowly on watchOS.
1616
// UNSUPPORTED: OS=watchos
1717

1818
public enum ApproximateCount {
1919
case Unknown
20-
case Precise(IntMax)
21-
case Underestimate(IntMax)
22-
case Overestimate(IntMax)
20+
case Precise(Int64)
21+
case Underestimate(Int64)
22+
case Overestimate(Int64)
2323
}
2424

2525
public protocol ApproximateCountableSequence : Sequence {

0 commit comments

Comments
 (0)