Skip to content

Commit c9e8588

Browse files
authored
Merge pull request swiftlang#30182 from scentini/enum-cxx
2 parents 80cc726 + 396ba4f commit c9e8588

File tree

12 files changed

+54
-51
lines changed

12 files changed

+54
-51
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
enum {
2+
Constant1,
3+
Constant2
4+
};
5+
6+
enum {
7+
VarConstant1,
8+
VarConstant2
9+
} global;
10+
11+
typedef struct SR2511 {
12+
int x;
13+
14+
enum {
15+
SR2511A = 0, SR2511B, SR2511C
16+
} y;
17+
18+
int z;
19+
} SR2511;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module EnumAnon {
2+
header "enum-anon.h"
3+
}
4+
5+
module EnumExhaustivity {
6+
header "EnumExhaustivity.h"
7+
export *
8+
}

test/ClangImporter/enum-anon-sized.swift renamed to test/CXXInterop/enum/enum-anon-sized.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// RUN: %target-swift-frontend -emit-ir %s -enable-objc-interop -import-objc-header %S/Inputs/enum-anon.h | %FileCheck -check-prefix=CHECK -check-prefix=CHECK-%target-runtime %s
1+
// RUN: %target-swift-frontend -emit-ir %s -I %S/Inputs | %FileCheck -check-prefix=CHECK %s
2+
// RUN: %target-swift-frontend -emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck -check-prefix=CHECK %s
3+
4+
import EnumAnon
25

36
func verifyIsInt(_: inout Int) { }
47
func verifyIsInt32(_: inout Int32) { }
@@ -23,11 +26,6 @@ public func testIR(x: UnsafePointer<SR2511>) -> CInt {
2326
// CHECK: store i32 1, i32* getelementptr inbounds ([[ENUM_TYPE]], [[ENUM_TYPE]]* bitcast (i32* @global to [[ENUM_TYPE]]*), i32 0, i32 0), align 4
2427
global = VarConstant2
2528

26-
#if _runtime(_ObjC)
27-
// CHECK-objc: store i16 1, i16* getelementptr inbounds (%Ts6UInt16V, %Ts6UInt16V* bitcast (i16* @usGlobal to %Ts6UInt16V*), i32 0, i32 0), align 2
28-
usGlobal = USVarConstant2
29-
#endif
30-
3129
// Force the definition of the type above.
3230
// CHECK: ret
3331
return x.pointee.z

test/CXXInterop/enum/enum-anon.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %target-swift-frontend -typecheck %s -I %S/Inputs -DDIAGS -verify
2+
// RUN: %target-swift-frontend -typecheck %s -enable-cxx-interop -I %S/Inputs -DDIAGS -verify
3+
import EnumAnon
4+
5+
func testDiags() {
6+
7+
let us2: UInt16 = 0
8+
let _: String = us2 // expected-error {{cannot convert value of type 'UInt16' to specified type 'String'}}
9+
10+
let usVar2: UInt16 = 0
11+
let _: String = usVar2 // expected-error {{cannot convert value of type 'UInt16' to specified type 'String'}}
12+
13+
// The nested anonymous enum value should still have top-level scope, because
14+
// that's how C works. It should also have the same type as the field (above).
15+
let _: String = SR2511.SR2511B // expected-error {{type 'SR2511' has no member 'SR2511B'}}
16+
}
17+

test/ClangImporter/enum-cxx.swift renamed to test/CXXInterop/enum/enum-cxx.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -emit-ir -primary-file %s -I %S/Inputs/custom-modules -module-cache-path %t -enable-cxx-interop -o - | %FileCheck %s
1+
// RUN: %target-swift-frontend -emit-ir -primary-file %s -I %S/../../ClangImporter/Inputs/ -module-cache-path %t -enable-cxx-interop -o - | %FileCheck %s
22

33
import CXXInterop
44

test/ClangImporter/enum-exhaustivity-system.swift renamed to test/CXXInterop/enum/enum-exhaustivity-system.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -typecheck %s -Xcc -isystem -Xcc %S/Inputs/custom-modules -verify -enable-nonfrozen-enum-exhaustivity-diagnostics
1+
// RUN: %target-swift-frontend -typecheck %s -Xcc -isystem -Xcc %S/Inputs -verify -enable-nonfrozen-enum-exhaustivity-diagnostics
22

33
import EnumExhaustivity
44

test/ClangImporter/enum-exhaustivity.swift renamed to test/CXXInterop/enum/enum-exhaustivity.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// RUN: %target-swift-frontend -typecheck %s -I %S/Inputs/custom-modules -verify -warnings-as-errors -enable-nonfrozen-enum-exhaustivity-diagnostics
1+
// RUN: %target-swift-frontend -typecheck %s -I %S/Inputs -verify -warnings-as-errors -enable-nonfrozen-enum-exhaustivity-diagnostics
22

3-
// RUN: %target-swift-ide-test -source-filename %s -print-module -module-to-print EnumExhaustivity -I %S/Inputs/custom-modules | %FileCheck %s
3+
// RUN: %target-swift-ide-test -source-filename %s -print-module -module-to-print EnumExhaustivity -I %S/Inputs | %FileCheck %s
44

55
// CHECK-LABEL: {{^}}enum RegularEnum : {{.+}} {
66
// CHECK: case A

test/ClangImporter/Inputs/custom-modules/module.map

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ module ctypes_bits_exported {
4545
export *
4646
}
4747

48-
module EnumExhaustivity {
49-
header "EnumExhaustivity.h"
50-
export *
51-
}
52-
5348
module ExternIntX { header "x.h" }
5449

5550
module HasSubmodule {

test/ClangImporter/Inputs/enum-anon.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,3 @@
1-
enum {
2-
Constant1,
3-
Constant2
4-
};
5-
6-
enum {
7-
VarConstant1,
8-
VarConstant2
9-
} global;
10-
11-
typedef struct SR2511 {
12-
int x;
13-
14-
enum {
15-
SR2511A = 0, SR2511B, SR2511C
16-
} y;
17-
18-
int z;
19-
} SR2511;
20-
21-
#if __OBJC__
221
enum : unsigned short {
232
USConstant1,
243
USConstant2
@@ -28,4 +7,3 @@ enum : unsigned short {
287
USVarConstant1,
298
USVarConstant2
309
} usGlobal;
31-
#endif // __OBJC__

test/ClangImporter/enum-anon.swift

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
// RUN: %target-swift-frontend -typecheck %s -enable-objc-interop -import-objc-header %S/Inputs/enum-anon.h -DDIAGS -verify
22

3+
// REQUIRES: objc_interop
4+
35
func testDiags() {
4-
#if _runtime(_ObjC)
56
let us2 = USConstant2
6-
#else
7-
let us2: UInt16 = 0
8-
#endif
97
let _: String = us2 // expected-error {{cannot convert value of type 'UInt16' to specified type 'String'}}
10-
11-
#if _runtime(_ObjC)
128
let usVar2 = USVarConstant2
13-
#else
14-
let usVar2: UInt16 = 0
15-
#endif
169
let _: String = usVar2 // expected-error {{cannot convert value of type 'UInt16' to specified type 'String'}}
17-
18-
// The nested anonymous enum value should still have top-level scope, because
19-
// that's how C works. It should also have the same type as the field (above).
20-
let _: String = SR2511.SR2511B // expected-error {{type 'SR2511' has no member 'SR2511B'}}
2110
}
22-

0 commit comments

Comments
 (0)