Skip to content

IRGen: Also list specialized generic class' objective c ro data in the dedicated linker section #75595

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
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
15 changes: 14 additions & 1 deletion lib/IRGen/GenClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,12 @@ namespace {
}

auto dataPtr = emitROData(ForMetaClass, DoesNotHaveUpdateCallback);

// Record the ro-data globals if this is a pre-specialized class.
if (specializedGenericType) {
IGM.addGenericROData(dataPtr);
}

dataPtr = llvm::ConstantExpr::getPtrToInt(dataPtr, IGM.IntPtrTy);

llvm::Constant *fields[] = {
Expand Down Expand Up @@ -2684,7 +2690,14 @@ static llvm::Constant *doEmitClassPrivateData(
}

// Then build the class RO-data.
return builder.emitROData(ForClass, hasUpdater);
auto res = builder.emitROData(ForClass, hasUpdater);

// Record the ro-data globals if this is a pre-specialized class.
if (classUnion.isa<std::pair<ClassDecl*, CanType>>()) {
IGM.addGenericROData(res);
}

return res;
}

llvm::Constant *irgen::emitSpecializedGenericClassPrivateData(
Expand Down
32 changes: 31 additions & 1 deletion test/IRGen/generic_class_rodata_list.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -enable-emit-generic-class-ro_t-list -S %s -o - | %FileCheck %s
// RUN: %target-swift-frontend -prespecialize-generic-metadata -target %target-cpu-apple-macosx12.0 -enable-emit-generic-class-ro_t-list -S %s -o - | %FileCheck %s
// REQUIRES: objc_interop
// REQUIRES: CPU=x86_64 || CPU=arm64
// REQUIRES: OS=macosx
Expand Down Expand Up @@ -30,11 +30,33 @@
// CHECK: .quad 0
// CHECK: .quad __CLASS_METHODS__TtC25generic_class_rodata_list9Somethin


// CHECK: __METACLASS_DATA_$s25generic_class_rodata_list9SomethingCySuGMf:
// CHECK: .long 129
// CHECK: .long 40
// CHECK: .long 40
// CHECK: .long 0
// CHECK: .quad _$s25generic_class_rodata_list9SomethingCySuGMf+24
// CHECK: .quad 0
// CHECK: .quad __CLASS_METHODS_$s25generic_class_rodata_list9SomethingCySuGMf

// CHECK: __DATA_$s25generic_class_rodata_list9SomethingCySuGMf:
// CHECK: .long 128
// CHECK: .long 16
// CHECK: .long 16
// CHECK: .long 0
// CHECK: .quad 0
// CHECK: .quad 0
// CHECK: .quad __INSTANCE_METHODS_$s25generic_class_rodata_list9SomethingCySuGMf


// CHECK: .section __DATA,__objc_clsrolist
// CHECK: .p2align 3
// CHECK:_generic_ro_datas:
// CHECK: .quad ___unnamed_1+40
// CHECK: .quad ___unnamed_1+112
// CHECK: .quad __METACLASS_DATA_$s25generic_class_rodata_list9SomethingCySuGMf
// CHECK: .quad __DATA_$s25generic_class_rodata_list9SomethingCySuGMf

import Foundation

Expand All @@ -44,3 +66,11 @@ public class Something<T> {
@objc
public static func myStaticMethod() { print("static") }
}

public protocol P {
func t<T>(_ t: T)
}

public func some(_ arr : Something<UInt>, p: P) {
p.t(arr)
}