Skip to content

Commit 5eb25f1

Browse files
authored
Merge pull request #37664 from slavapestov/objc-enum-on-linux-5.5
Sema: Allow @objc enums without -enable-objc-interop or importing Foundation [5.5]
2 parents 4bcbcb6 + 75a9bfc commit 5eb25f1

File tree

4 files changed

+37
-24
lines changed

4 files changed

+37
-24
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,11 @@ static void diagnoseObjCAttrWithoutFoundation(ObjCAttr *attr, Decl *decl,
954954
if (attr->isImplicit())
955955
return;
956956

957+
// @objc enums do not require -enable-objc-interop or Foundation be have been
958+
// imported.
959+
if (isa<EnumDecl>(decl))
960+
return;
961+
957962
auto &ctx = SF->getASTContext();
958963

959964
if (!ctx.LangOpts.EnableObjCInterop) {

test/IRGen/objc_enum.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s
2+
3+
// REQUIRES: CPU=x86_64
4+
5+
@objc public enum ExportedToObjC: Int32 {
6+
case Foo = -1, Bar, Bas
7+
}
8+
9+
// CHECK-LABEL: define{{( protected)?( dllexport)?}} swiftcc i32 @"$s9objc_enum0a1_B7_injectAA14ExportedToObjCOyF"()
10+
// CHECK: ret i32 -1
11+
public func objc_enum_inject() -> ExportedToObjC {
12+
return .Foo
13+
}
14+
15+
// CHECK-LABEL: define{{( protected)?( dllexport)?}} swiftcc i64 @"$s9objc_enum0a1_B7_switchySiAA14ExportedToObjCOF"(i32 %0)
16+
// CHECK: switch i32 %0, label {{%.*}} [
17+
// CHECK: i32 -1, label {{%.*}}
18+
// CHECK: i32 0, label {{%.*}}
19+
// CHECK: i32 1, label {{%.*}}
20+
public func objc_enum_switch(_ x: ExportedToObjC) -> Int {
21+
switch x {
22+
case .Foo:
23+
return 0
24+
case .Bar:
25+
return 1
26+
case .Bas:
27+
return 2
28+
}
29+
}
30+

test/IRGen/objc_ns_enum.swift

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -99,28 +99,6 @@ use_metadata(NSRuncingOptions.mince)
9999
case Foo = -1, Bar, Bas
100100
}
101101

102-
// CHECK-LABEL: define hidden swiftcc i64 @"$s12objc_ns_enum0a1_C7_injectAA14ExportedToObjCOyF"()
103-
// CHECK: ret i64 -1
104-
func objc_enum_inject() -> ExportedToObjC {
105-
return .Foo
106-
}
107-
108-
// CHECK-LABEL: define hidden swiftcc i64 @"$s12objc_ns_enum0a1_C7_switchySiAA14ExportedToObjCOF"(i64 %0)
109-
// CHECK: switch i64 %0, label {{%.*}} [
110-
// CHECK: i64 -1, label {{%.*}}
111-
// CHECK: i64 0, label {{%.*}}
112-
// CHECK: i64 1, label {{%.*}}
113-
func objc_enum_switch(_ x: ExportedToObjC) -> Int {
114-
switch x {
115-
case .Foo:
116-
return 0
117-
case .Bar:
118-
return 1
119-
case .Bas:
120-
return 2
121-
}
122-
}
123-
124102
@objc class ObjCEnumMethods : NSObject {
125103
// CHECK: define internal void @"$s12objc_ns_enum15ObjCEnumMethodsC0C2InyyAA010ExportedToD1COFTo"([[OBJC_ENUM_METHODS:.*]]* %0, i8* %1, i64 %2)
126104
@objc dynamic func enumIn(_ x: ExportedToObjC) {}

test/SILGen/enum_raw_representable_objc.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %target-swift-emit-silgen -emit-sorted-sil -enable-objc-interop -disable-objc-attr-requires-foundation-module %s | %FileCheck %s
2-
// RUN: %target-swift-emit-silgen -emit-sorted-sil -enable-objc-interop -disable-objc-attr-requires-foundation-module -enable-library-evolution %s | %FileCheck -check-prefix=CHECK-RESILIENT %s
1+
// RUN: %target-swift-emit-silgen -emit-sorted-sil %s | %FileCheck %s
2+
// RUN: %target-swift-emit-silgen -emit-sorted-sil -enable-library-evolution %s | %FileCheck -check-prefix=CHECK-RESILIENT %s
33

44
#if os(Windows) && arch(x86_64)
55
@objc public enum CLike: Int32 {

0 commit comments

Comments
 (0)