Skip to content

Commit b8ef3ff

Browse files
kubamracekartemcm
authored andcommitted
Add test/ConstValues/Conditions.swift
1 parent a925d6a commit b8ef3ff

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/ConstValues/Conditions.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Constant globals on comparisons and conditions
2+
3+
// RUN: %target-swift-frontend -emit-ir -primary-file %s -parse-as-library
4+
5+
_const let constGlobal1: Int = true ? 1 : 0
6+
_const let constGlobal2: Int = (2 * 4 == 8) ? 1 : 0
7+
_const let constGlobal3: Int = (10 > 20) ? 10 : 20
8+
//_const let constGlobal4: Int = max(10, 20)
9+
_const let constGlobal5: Bool = 10 > 20
10+
_const let constGlobal6: Int = constGlobal5 ? 10 : 20
11+
12+
_const let number: UInt8 = 0xf0
13+
14+
_const let bit0: Bool = (number & 0b0000_0001) != 0
15+
_const let bit1: Bool = (number & 0b0000_0010) != 0
16+
_const let bit2: Bool = (number & 0b0000_0100) != 0
17+
_const let bit3: Bool = (number & 0b0000_1000) != 0
18+
_const let bit4: Bool = (number & 0b0001_0000) != 0
19+
_const let bit5: Bool = (number & 0b0010_0000) != 0
20+
_const let bit6: Bool = (number & 0b0100_0000) != 0
21+
_const let bit7: Bool = (number & 0b1000_0000) != 0
22+
23+
_const let bits0_0: UInt8 = ((bit0 ? 0b0000_0001 : 0b0000_0000) << 0)
24+
_const let bits0_1: UInt8 = bits0_0 | ((bit1 ? 0b0000_0001 : 0b0000_0000) << 1)
25+
_const let bits0_2: UInt8 = bits0_1 | ((bit2 ? 0b0000_0001 : 0b0000_0000) << 2)
26+
_const let bits0_3: UInt8 = bits0_2 | ((bit3 ? 0b0000_0001 : 0b0000_0000) << 3)
27+
_const let bits0_4: UInt8 = bits0_3 | ((bit4 ? 0b0000_0001 : 0b0000_0000) << 4)
28+
_const let bits0_5: UInt8 = bits0_4 | ((bit5 ? 0b0000_0001 : 0b0000_0000) << 5)
29+
_const let bits0_6: UInt8 = bits0_5 | ((bit6 ? 0b0000_0001 : 0b0000_0000) << 6)
30+
_const let bits0_7: UInt8 = bits0_6 | ((bit7 ? 0b0000_0001 : 0b0000_0000) << 7)
31+
32+
_const let numberBackIsRight: Bool = bits0_7 == 0xf0

0 commit comments

Comments
 (0)