Skip to content
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

[5.3] IRGen: ObjC method lists are not const. #33338

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 15 additions & 7 deletions lib/IRGen/GenClass.cpp
Expand Up @@ -1257,7 +1257,7 @@ namespace {
// };

assert(fields.getNextOffsetFromGlobal() == size);
return buildGlobalVariable(fields, "_CATEGORY_");
return buildGlobalVariable(fields, "_CATEGORY_", /*const*/ true);
}

llvm::Constant *emitProtocol() {
Expand Down Expand Up @@ -1309,7 +1309,7 @@ namespace {
// };

assert(fields.getNextOffsetFromGlobal() == size);
return buildGlobalVariable(fields, "_PROTOCOL_");
return buildGlobalVariable(fields, "_PROTOCOL_", /*const*/ true);
}

void emitRODataFields(ConstantStructBuilder &b,
Expand Down Expand Up @@ -1402,7 +1402,7 @@ namespace {
emitRODataFields(fields, forMeta, hasUpdater);

auto dataSuffix = forMeta ? "_METACLASS_DATA_" : "_DATA_";
return buildGlobalVariable(fields, dataSuffix);
return buildGlobalVariable(fields, dataSuffix, /*const*/ true);
}

private:
Expand Down Expand Up @@ -1636,7 +1636,8 @@ namespace {
return null();
}

return buildGlobalVariable(array, "_PROTOCOL_METHOD_TYPES_");
return buildGlobalVariable(array, "_PROTOCOL_METHOD_TYPES_",
/*const*/ true);
}

void buildExtMethodTypes(ConstantArrayBuilder &array,
Expand All @@ -1661,6 +1662,7 @@ namespace {
llvm::Constant *buildMethodList(ArrayRef<MethodDescriptor> methods,
StringRef name) {
return buildOptionalList(methods, 3 * IGM.getPointerSize(), name,
/*isConst*/ false,
[&](ConstantArrayBuilder &descriptors,
MethodDescriptor descriptor) {
buildMethod(descriptors, descriptor);
Expand All @@ -1686,6 +1688,7 @@ namespace {
chooseNamePrefix("_PROTOCOLS_",
"_CATEGORY_PROTOCOLS_",
"_PROTOCOL_PROTOCOLS_"),
/*isConst*/ true,
[&](ConstantArrayBuilder &descriptors,
ProtocolDecl *protocol) {
buildProtocol(descriptors, protocol);
Expand Down Expand Up @@ -1799,6 +1802,7 @@ namespace {
llvm::Constant *buildIvarList() {
Size eltSize = 3 * IGM.getPointerSize() + Size(8);
return buildOptionalList(Ivars, eltSize, "_IVARS_",
/*constant*/ true,
[&](ConstantArrayBuilder &descriptors,
VarDecl *ivar) {
buildIvar(descriptors, ivar);
Expand Down Expand Up @@ -1934,6 +1938,7 @@ namespace {
StringRef namePrefix) {
Size eltSize = 2 * IGM.getPointerSize();
return buildOptionalList(properties, eltSize, namePrefix,
/*constant*/ true,
[&](ConstantArrayBuilder &descriptors,
VarDecl *property) {
buildProperty(descriptors, property);
Expand All @@ -1952,6 +1957,7 @@ namespace {
llvm::Constant *buildOptionalList(const C &objects,
Size optionalEltSize,
StringRef nameBase,
bool isConst,
Fn &&buildElement) {
if (objects.empty())
return null();
Expand Down Expand Up @@ -1990,7 +1996,7 @@ namespace {

fields.fillPlaceholderWithInt(countPosition, countType, count);

return buildGlobalVariable(fields, nameBase);
return buildGlobalVariable(fields, nameBase, isConst);
}

/// Get the name of the class or protocol to mangle into the ObjC symbol
Expand All @@ -2010,7 +2016,8 @@ namespace {
/// Build a private global variable as a structure containing the
/// given fields.
template <class B>
llvm::Constant *buildGlobalVariable(B &fields, StringRef nameBase) {
llvm::Constant *buildGlobalVariable(B &fields, StringRef nameBase,
bool isConst) {
llvm::SmallString<64> nameBuffer;
auto var =
fields.finishAndCreateGlobal(Twine(nameBase)
Expand All @@ -2024,7 +2031,8 @@ namespace {

switch (IGM.TargetInfo.OutputObjectFormat) {
case llvm::Triple::MachO:
var->setSection("__DATA, __objc_const");
var->setSection(isConst ? "__DATA, __objc_const"
: "__DATA, __objc_data");
break;
case llvm::Triple::XCOFF:
case llvm::Triple::COFF:
Expand Down
2 changes: 1 addition & 1 deletion test/IRGen/class_update_callback_with_fixed_layout.sil
Expand Up @@ -51,7 +51,7 @@ sil_vtable SubclassOfClassWithResilientField {}
// -- the update callback
// CHECK-SAME: @"$s39class_update_callback_with_fixed_layout23ClassWithResilientFieldCMU"

// CHECK-SAME: }, section "__DATA, __objc_const", align 8
// CHECK-SAME: }, section "__DATA, {{.*}}", align 8

// Class has static metadata:
// CHECK-LABEL: @"$s39class_update_callback_with_fixed_layout23ClassWithResilientFieldCMf"
Expand Down
2 changes: 1 addition & 1 deletion test/IRGen/class_update_callback_without_fixed_layout.sil
Expand Up @@ -63,7 +63,7 @@ sil_vtable SubclassOfClassWithResilientField {}
// -- the update callback
// CHECK-NEW-SAME: @"$s42class_update_callback_without_fixed_layout23ClassWithResilientFieldCMU{{(\.ptrauth)?}}"

// CHECK-SAME: }, section "__DATA, __objc_const"
// CHECK-SAME: }, section "__DATA, {{.*}}"

// Class has static metadata:
// CHECK-LABEL: @"$s42class_update_callback_without_fixed_layout23ClassWithResilientFieldCMf"
Expand Down
2 changes: 1 addition & 1 deletion test/IRGen/objc_bridge.swift
Expand Up @@ -96,7 +96,7 @@ import Foundation
// CHECK: i8* bitcast (void ([[OPAQUE:.*]]*, i8*)* @"$s11objc_bridge3BasCfETo" to i8*)
// CHECK: }
// CHECK: ]
// CHECK: }, section "__DATA, __objc_const", align 8
// CHECK: }, section "__DATA, {{.*}}", align 8

// CHECK: @_PROPERTIES__TtC11objc_bridge3Bas = internal constant { i32, i32, [5 x { i8*, i8* }] } {

Expand Down
4 changes: 2 additions & 2 deletions test/IRGen/objc_class_export.swift
Expand Up @@ -34,7 +34,7 @@
// CHECK-SAME: i8* null,
// CHECK-SAME: i8* null,
// CHECK-SAME: i8* null
// CHECK-SAME: }, section "__DATA, __objc_const", align 8
// CHECK-SAME: }, section "__DATA, {{.*}}", align 8
// CHECK: @_DATA__TtC17objc_class_export3Foo = internal constant {{.*\*}} } {
// CHECK-SAME: i32 128,
// CHECK-SAME: i32 16,
Expand All @@ -47,7 +47,7 @@
// CHECK-SAME: @_IVARS__TtC17objc_class_export3Foo,
// CHECK-SAME: i8* null,
// CHECK-SAME: _PROPERTIES__TtC17objc_class_export3Foo
// CHECK-SAME: }, section "__DATA, __objc_const", align 8
// CHECK-SAME: }, section "__DATA, {{.*}}", align 8
// CHECK: @"$s17objc_class_export3FooCMf" = internal global <{{.*}} }> <{
// CHECK-SAME: void ([[FOO]]*)* @"$s17objc_class_export3FooCfD",
// CHECK-SAME: i8** @"$sBOWV",
Expand Down
16 changes: 8 additions & 8 deletions test/IRGen/objc_extensions.swift
Expand Up @@ -27,7 +27,7 @@ import objc_extension_base
// CHECK-SAME: @"_CATEGORY_CLASS_METHODS_Gizmo_$_objc_extensions",
// CHECK-SAME: @"_CATEGORY_PROTOCOLS_Gizmo_$_objc_extensions",
// CHECK-SAME: i8* null
// CHECK-SAME: }, section "__DATA, __objc_const", align 8
// CHECK-SAME: }, section "__DATA, {{.*}}", align 8

@objc protocol NewProtocol {
func brandNewInstanceMethod()
Expand Down Expand Up @@ -67,7 +67,7 @@ extension Gizmo: NewProtocol {
// CHECK: {{.*}} @"_CATEGORY_CLASS_METHODS_Gizmo_$_objc_extensions1",
// CHECK: i8* null,
// CHECK: i8* null
// CHECK: }, section "__DATA, __objc_const", align 8
// CHECK: }, section "__DATA, {{.*}}", align 8

extension Gizmo {
@objc func brandSpankingNewInstanceMethod() {
Expand All @@ -92,7 +92,7 @@ class Hoozit : NSObject {
// CHECK: i8* getelementptr inbounds ([8 x i8], [8 x i8]* [[STR:@.*]], i64 0, i64 0),
// CHECK: i8* bitcast (void ([[OPAQUE:%.*]]*, i8*)* @"$s15objc_extensions6HoozitC7blibbleyyFTo" to i8*)
// CHECK: }]
// CHECK: }, section "__DATA, __objc_const", align 8
// CHECK: }, section "__DATA, {{.*}}", align 8

// CHECK-LABEL: @"_CATEGORY_CLASS_METHODS__TtC15objc_extensions6Hoozit_$_objc_extensions" = internal constant
// CHECK: i32 24,
Expand All @@ -102,7 +102,7 @@ class Hoozit : NSObject {
// CHECK: i8* getelementptr inbounds ([8 x i8], [8 x i8]* [[STR]], i64 0, i64 0),
// CHECK: i8* bitcast (void (i8*, i8*)* @"$s15objc_extensions6HoozitC7blobbleyyFZTo" to i8*)
// CHECK: }]
// CHECK: }, section "__DATA, __objc_const", align 8
// CHECK: }, section "__DATA, {{.*}}", align 8

// CHECK-LABEL: @"_CATEGORY__TtC15objc_extensions6Hoozit_$_objc_extensions" = internal constant
// CHECK: i8* getelementptr inbounds ([16 x i8], [16 x i8]* [[CATEGORY_NAME]], i64 0, i64 0),
Expand All @@ -111,7 +111,7 @@ class Hoozit : NSObject {
// CHECK: {{.*}} @"_CATEGORY_CLASS_METHODS__TtC15objc_extensions6Hoozit_$_objc_extensions",
// CHECK: i8* null,
// CHECK: i8* null
// CHECK: }, section "__DATA, __objc_const", align 8
// CHECK: }, section "__DATA, {{.*}}", align 8

extension Hoozit {
@objc func blibble() { }
Expand All @@ -127,7 +127,7 @@ class SwiftOnly { }
// CHECK: i8* getelementptr inbounds ([7 x i8], [7 x i8]* @"\01L_selector_data(wibble)", i64 0, i64 0),
// CHECK: i8* getelementptr inbounds ([8 x i8], [8 x i8]* [[STR]], i64 0, i64 0),
// CHECK: i8* bitcast (void (i8*, i8*)* @"$s15objc_extensions9SwiftOnlyC6wibbleyyFTo" to i8*)
// CHECK: }] }, section "__DATA, __objc_const", align 8
// CHECK: }] }, section "__DATA, {{.*}}", align 8
extension SwiftOnly {
@objc func wibble() { }
}
Expand Down Expand Up @@ -157,7 +157,7 @@ extension NSObject {
// CHECK-SAME: i8* getelementptr inbounds ([16 x i8], [16 x i8]* [[CATEGORY_NAME]], i64 0, i64 0),
// CHECK-SAME: @"_CATEGORY_INSTANCE_METHODS__TtCC15objc_extensions5Outer5Inner_$_objc_extensions",
// CHECK-SAME: i8* null
// CHECK-SAME: }, section "__DATA, __objc_const", align 8
// CHECK-SAME: }, section "__DATA, {{.*}}", align 8

class Outer : NSObject {
class Inner : NSObject {}
Expand All @@ -175,7 +175,7 @@ class NSDogcow : NSObject {}

// CHECK: [[NAME:@.*]] = private unnamed_addr constant [5 x i8] c"woof\00"
// CHECK: [[ATTR:@.*]] = private unnamed_addr constant [7 x i8] c"Tq,N,D\00"
// CHECK: @"_CATEGORY_PROPERTIES__TtC15objc_extensions8NSDogcow_$_objc_extensions" = internal constant {{.*}} [[NAME]], {{.*}} [[ATTR]], {{.*}}, section "__DATA, __objc_const", align 8
// CHECK: @"_CATEGORY_PROPERTIES__TtC15objc_extensions8NSDogcow_$_objc_extensions" = internal constant {{.*}} [[NAME]], {{.*}} [[ATTR]], {{.*}}, section "__DATA, {{.*}}", align 8
extension NSDogcow {
@NSManaged var woof: Int
}
Expand Down
4 changes: 2 additions & 2 deletions test/IRGen/objc_methods.swift
Expand Up @@ -79,7 +79,7 @@ class ObjcDestructible: NSObject {
// CHECK-macosx: i8* bitcast (i8 (i8*, i8*, %4**)* @"$s12objc_methods3FooC4failyyKFTo" to i8*)
// CHECK-ios: i8* bitcast (i1 (i8*, i8*, %4**)* @"$s12objc_methods3FooC4failyyKFTo" to i8*)
// CHECK: }]
// CHECK: }, section "__DATA, __objc_const", align 8
// CHECK: }, section "__DATA, {{.*}}", align 8
// CHECK: @_INSTANCE_METHODS__TtC12objc_methods16ObjcDestructible = internal constant { {{.*}}] } {
// CHECK: i32 24,
// CHECK: i32 2,
Expand All @@ -88,7 +88,7 @@ class ObjcDestructible: NSObject {
// CHECK: i8* getelementptr inbounds ([8 x i8], [8 x i8]* [[NO_ARGS_SIGNATURE]], i64 0, i64 0),
// CHECK: i8* bitcast (void (%6*, i8*)* @"$s12objc_methods16ObjcDestructibleCfETo" to i8*) }]
// CHECK: }]
// CHECK: }, section "__DATA, __objc_const", align 8
// CHECK: }, section "__DATA, {{.*}}", align 8
// CHECK: [[BLOCK_SIGNATURE_EXT_1:@.*]] = private unnamed_addr constant [18 x i8] c"v24@0:8@?<q@?q>16\00"
// CHECK: [[BLOCK_SIGNATURE_EXT_2:@.*]] = private unnamed_addr constant [19 x i8] c"v24@0:8@?<q@?qq>16\00"
// CHECK: [[STRING_SIGNATURE_EXT:@.*]] = private unnamed_addr constant [31 x i8] c"@\22NSString\2224@0:8@\22NSString\2216\00"
Expand Down
24 changes: 12 additions & 12 deletions test/IRGen/objc_properties.swift
Expand Up @@ -112,7 +112,7 @@ class SomeWrapperTests {
// CHECK-NEW: i8* getelementptr inbounds ([11 x i8], [11 x i8]* [[SHARED_NAME]], i64 0, i64 0),
// CHECK-NEW: i8* getelementptr inbounds ([5 x i8], [5 x i8]* [[SHARED_ATTRS]], i64 0, i64 0)
// CHECK-NEW: }]
// CHECK-NEW: }, section "__DATA, __objc_const", align 8
// CHECK-NEW: }, section "__DATA, {{.*}}", align 8

// CHECK: @_METACLASS_DATA__TtC15objc_properties10SomeObject = internal constant { {{.*}} } {
// CHECK-SAME: i32 {{[0-9]+}}, i32 {{[0-9]+}}, i32 {{[0-9]+}}, i32 {{[0-9]+}},
Expand All @@ -122,7 +122,7 @@ class SomeWrapperTests {
// CHECK-SAME: i8* null, i8* null, i8* null,
// CHECK-NEW-SAME: { {{.+}} }* @_CLASS_PROPERTIES__TtC15objc_properties10SomeObject
// CHECK-OLD-SAME: i8* null
// CHECK-SAME: }, section "__DATA, __objc_const", align 8
// CHECK-SAME: }, section "__DATA, {{.*}}", align 8

// CHECK: [[GETTER_SIGNATURE:@.*]] = private unnamed_addr constant [8 x i8] c"@16@0:8\00"
// CHECK: [[SETTER_SIGNATURE:@.*]] = private unnamed_addr constant [11 x i8] c"v24@0:8@16\00"
Expand Down Expand Up @@ -163,7 +163,7 @@ class SomeWrapperTests {
// CHECK: i8* getelementptr inbounds ([8 x i8], [8 x i8]* [[GETTER_SIGNATURE]], i64 0, i64 0),
// CHECK: @"$s15objc_properties10SomeObjectCACycfcTo{{(.ptrauth)?}}"
// CHECK: }]
// CHECK: }, section "__DATA, __objc_const", align 8
// CHECK: }, section "__DATA, {{.*}}", align 8

// This appears earlier because it's also used in an ivar description.
// CHECK: [[BAREIVAR_NAME:@.*]] = private unnamed_addr constant [9 x i8] c"bareIvar\00"
Expand Down Expand Up @@ -195,7 +195,7 @@ class SomeWrapperTests {
// CHECK: i8* getelementptr inbounds ([7 x i8], [7 x i8]* [[WIBBLE_NAME]], i64 0, i64 0),
// CHECK: i8* getelementptr inbounds ([50 x i8], [50 x i8]* [[WIBBLE_ATTRS]], i64 0, i64 0)
// CHECK: }]
// CHECK: }, section "__DATA, __objc_const", align 8
// CHECK: }, section "__DATA, {{.*}}", align 8

// CHECK: @_DATA__TtC15objc_properties10SomeObject = internal constant { {{.+}} } {
// CHECK: i32 {{[0-9]+}}, i32 {{[0-9]+}}, i32 {{[0-9]+}}, i32 {{[0-9]+}},
Expand All @@ -206,7 +206,7 @@ class SomeWrapperTests {
// CHECK: { {{.+}} }* @_IVARS__TtC15objc_properties10SomeObject,
// CHECK: i8* null,
// CHECK: { {{.+}} }* @_PROPERTIES__TtC15objc_properties10SomeObject
// CHECK: }, section "__DATA, __objc_const", align 8
// CHECK: }, section "__DATA, {{.*}}", align 8

// CHECK: @"_CATEGORY_INSTANCE_METHODS__TtC15objc_properties10SomeObject_$_objc_properties" = internal constant { {{.*}}] } {
// CHECK: i32 24,
Expand All @@ -220,7 +220,7 @@ class SomeWrapperTests {
// CHECK: i8* getelementptr inbounds ([11 x i8], [11 x i8]* [[SETTER_SIGNATURE]], i64 0, i64 0),
// CHECK: @"$s15objc_properties10SomeObjectC17extensionPropertyACvsTo{{(.ptrauth)?}}"
// CHECK: }]
// CHECK: }, section "__DATA, __objc_const", align 8
// CHECK: }, section "__DATA, {{.*}}", align 8

// CHECK: [[EXTENSIONPROPERTY_NAME:@.*]] = private unnamed_addr constant [18 x i8] c"extensionProperty\00"

Expand All @@ -231,7 +231,7 @@ class SomeWrapperTests {
// CHECK: i8* getelementptr inbounds ([18 x i8], [18 x i8]* [[EXTENSIONPROPERTY_NAME]], i64 0, i64 0),
// CHECK: i8* getelementptr inbounds ([42 x i8], [42 x i8]* [[READWRITE_ATTRS]], i64 0, i64 0)
// CHECK: }]
// CHECK: }, section "__DATA, __objc_const", align 8
// CHECK: }, section "__DATA, {{.*}}", align 8

// CHECK-NEW: [[EXTENSIONCLASSPROPERTY_NAME:@.*]] = private unnamed_addr constant [19 x i8] c"extensionClassProp\00"
// CHECK-NEW: [[EXTENSIONCLASSPROPERTY_ATTRS:@.*]] = private unnamed_addr constant [7 x i8] c"T#,N,R\00"
Expand All @@ -246,7 +246,7 @@ class SomeWrapperTests {
// CHECK-NEW: }, {
// CHECK-NEW: i8* getelementptr inbounds ([26 x i8], [26 x i8]* [[EXTENSIONSTATICPROPERTY_NAME]], i64 0, i64 0),
// CHECK-NEW: i8* getelementptr inbounds ([5 x i8], [5 x i8]* [[SHARED_ATTRS]], i64 0, i64 0) }]
// CHECK-NEW: }, section "__DATA, __objc_const", align 8
// CHECK-NEW: }, section "__DATA, {{.*}}", align 8

// CHECK: @"_CATEGORY__TtC15objc_properties10SomeObject_$_objc_properties" = internal constant { {{.+}} } {
// CHECK: i8* getelementptr inbounds ([{{.+}} x i8], [{{.+}} x i8]* {{@.+}}, i64 0, i64 0),
Expand All @@ -258,7 +258,7 @@ class SomeWrapperTests {
// CHECK-NEW: { {{.+}} }* @"_CATEGORY_CLASS_PROPERTIES__TtC15objc_properties10SomeObject_$_objc_properties",
// CHECK-OLD: i8* null,
// CHECK: i32 60
// CHECK: }, section "__DATA, __objc_const", align 8
// CHECK: }, section "__DATA, {{.*}}", align 8


// CHECK: @_INSTANCE_METHODS__TtC15objc_properties4Tree =
Expand All @@ -283,7 +283,7 @@ class SomeWrapperTests {
// CHECK: i8* null,
// CHECK-NEW: { {{.+}} }* @_PROTOCOL_CLASS_PROPERTIES__TtP15objc_properties5Proto_
// CHECK-OLD: i8* null
// CHECK: }, section "__DATA, __objc_const", align 8
// CHECK: }, section "__DATA, {{.*}}", align 8


// CHECK: [[PROTOCOLPROPERTY_NAME:@.+]] = private unnamed_addr constant [6 x i8] c"value\00"
Expand All @@ -296,7 +296,7 @@ class SomeWrapperTests {
// CHECK: i8* getelementptr inbounds ([6 x i8], [6 x i8]* [[PROTOCOLPROPERTY_NAME]], i64 0, i64 0),
// CHECK: i8* getelementptr inbounds ([7 x i8], [7 x i8]* [[PROTOCOLPROPERTY_ATTRS]], i64 0, i64 0)
// CHECK: }]
// CHECK: }, section "__DATA, __objc_const", align 8
// CHECK: }, section "__DATA, {{.*}}", align 8

// CHECK-NEW: [[PROTOCOLCLASSPROPERTY_NAME:@.+]] = private unnamed_addr constant [15 x i8] c"sharedInstance\00"
// CHECK-NEW: [[PROTOCOLCLASSPROPERTY_ATTRS:@.+]] = private unnamed_addr constant [7 x i8] c"T@,N,&\00"
Expand All @@ -308,4 +308,4 @@ class SomeWrapperTests {
// CHECK-NEW: i8* getelementptr inbounds ([15 x i8], [15 x i8]* [[PROTOCOLCLASSPROPERTY_NAME]], i64 0, i64 0),
// CHECK-NEW: i8* getelementptr inbounds ([7 x i8], [7 x i8]* [[PROTOCOLCLASSPROPERTY_ATTRS]], i64 0, i64 0)
// CHECK-NEW: }]
// CHECK-NEW: }, section "__DATA, __objc_const", align 8
// CHECK-NEW: }, section "__DATA, {{.*}}", align 8