Skip to content

Commit 14ae2c2

Browse files
committed
Add a test to check if OptionSet literals are fully folded
1 parent 80a734a commit 14ae2c2

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/SILOptimizer/optionset.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %target-swift-frontend -parse-as-library -primary-file %s -O -sil-verify-all -module-name=test -emit-sil | %FileCheck %s
2+
// RUN: %target-swift-frontend -parse-as-library -primary-file %s -Osize -sil-verify-all -module-name=test -emit-sil | %FileCheck %s
3+
// REQUIRES: swift_stdlib_no_asserts,optimized_stdlib
4+
5+
public struct TestOptions: OptionSet {
6+
public let rawValue: Int
7+
public init(rawValue: Int) { self.rawValue = rawValue }
8+
9+
static let first = TestOptions(rawValue: 1 << 0)
10+
static let second = TestOptions(rawValue: 1 << 1)
11+
static let third = TestOptions(rawValue: 1 << 2)
12+
static let fourth = TestOptions(rawValue: 1 << 3)
13+
}
14+
15+
// CHECK: sil @{{.*}}returnTestOptions{{.*}}
16+
// CHECK-NEXT: bb0:
17+
// CHECK-NEXT: integer_literal {{.*}}, 15
18+
// CHECK-NEXT: struct $Int
19+
// CHECK-NEXT: struct $TestOptions
20+
// CHECK-NEXT: return
21+
public func returnTestOptions() -> TestOptions {
22+
return [.first, .second, .third, .fourth]
23+
}
24+
25+
// CHECK: alloc_global @{{.*}}globalTestOptions{{.*}}
26+
// CHECK-NEXT: global_addr
27+
// CHECK-NEXT: integer_literal {{.*}}, 15
28+
// CHECK-NEXT: struct $Int
29+
// CHECK-NEXT: struct $TestOptions
30+
// CHECK-NEXT: store
31+
// CHECK-NEXT: tuple
32+
// CHECK-NEXT: return
33+
let globalTestOptions: TestOptions = [.first, .second, .third, .fourth]
34+

0 commit comments

Comments
 (0)