Skip to content

Commit 128d33c

Browse files
authored
Merge pull request swiftlang#18169 from ravikandhadai/InconsistentUnreachWarning
2 parents 90ca430 + 81fad3c commit 128d33c

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

stdlib/public/core/Integers.swift.gyb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3881,20 +3881,17 @@ ${assignmentOperatorComment(x.operator, True)}
38813881
return !(lhs == rhs)
38823882
}
38833883

3884-
@inlinable // FIXME(sil-serialize-all)
3885-
@inline(__always)
3884+
@_transparent
38863885
public static func <= (lhs: ${Self}, rhs: ${Self}) -> Bool {
38873886
return !(rhs < lhs)
38883887
}
38893888

3890-
@inlinable // FIXME(sil-serialize-all)
3891-
@inline(__always)
3889+
@_transparent
38923890
public static func >= (lhs: ${Self}, rhs: ${Self}) -> Bool {
38933891
return !(lhs < rhs)
38943892
}
38953893

3896-
@inlinable // FIXME(sil-serialize-all)
3897-
@inline(__always)
3894+
@_transparent
38983895
public static func > (lhs: ${Self}, rhs: ${Self}) -> Bool {
38993896
return rhs < lhs
39003897
}

test/SILOptimizer/unreachable_code.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,49 @@ func ifTrue() -> Int {
1515
return 0 // expected-warning {{will never be executed}}
1616
}
1717

18+
func testUnreachableIfBranch() -> Int {
19+
let a = 2
20+
let c: Int
21+
if a < 2 { // expected-note {{condition always evaluates to false}}
22+
c = 3 // expected-warning {{will never be executed}}
23+
} else {
24+
c = 4
25+
}
26+
return c
27+
}
28+
29+
func testUnreachableIfBranch2() -> Int {
30+
let a = 2
31+
let c: Int
32+
if a > 2 { // expected-note {{condition always evaluates to false}}
33+
c = 3 // expected-warning {{will never be executed}}
34+
} else {
35+
c = 4
36+
}
37+
return c
38+
}
39+
40+
func testUnreachableElseBranch() -> Int {
41+
let a = 2
42+
let c: Int
43+
if a == 2 { // expected-note {{condition always evaluates to true}}
44+
c = 3
45+
} else {
46+
c = 4 // expected-warning {{will never be executed}}
47+
}
48+
return c
49+
}
50+
51+
// FIXME: False Negative: <rdar://39516135>. No warnings are produced here
52+
// as the statements along the unreachable branches are marked implicit.
53+
// Unreachable code analysis suppresses warnings in such cases.
54+
func testQuestionMarkOperator() -> Int {
55+
let a = 2
56+
let c: Int
57+
c = (a < 2) ? 3 : 4
58+
return c
59+
}
60+
1861
// Work-around <rdar://problem/17687851> by ensuring there is
1962
// something that appears to be user code in unreachable blocks.
2063
func userCode() {}

0 commit comments

Comments
 (0)