Skip to content

[Stdlib] Make the comparison operatosr on concrete Int types transparent #18169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions stdlib/public/core/Integers.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -3882,20 +3882,17 @@ ${assignmentOperatorComment(x.operator, True)}
return !(lhs == rhs)
}

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

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

@inlinable // FIXME(sil-serialize-all)
@inline(__always)
@_transparent
public static func > (lhs: ${Self}, rhs: ${Self}) -> Bool {
return rhs < lhs
}
Expand Down
43 changes: 43 additions & 0 deletions test/SILOptimizer/unreachable_code.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,49 @@ func ifTrue() -> Int {
return 0 // expected-warning {{will never be executed}}
}

func testUnreachableIfBranch() -> Int {
let a = 2
let c: Int
if a < 2 { // expected-note {{condition always evaluates to false}}
c = 3 // expected-warning {{will never be executed}}
} else {
c = 4
}
return c
}

func testUnreachableIfBranch2() -> Int {
let a = 2
let c: Int
if a > 2 { // expected-note {{condition always evaluates to false}}
c = 3 // expected-warning {{will never be executed}}
} else {
c = 4
}
return c
}

func testUnreachableElseBranch() -> Int {
let a = 2
let c: Int
if a == 2 { // expected-note {{condition always evaluates to true}}
c = 3
} else {
c = 4 // expected-warning {{will never be executed}}
}
return c
}

// FIXME: False Negative: <rdar://39516135>. No warnings are produced here
// as the statements along the unreachable branches are marked implicit.
// Unreachable code analysis suppresses warnings in such cases.
func testQuestionMarkOperator() -> Int {
let a = 2
let c: Int
c = (a < 2) ? 3 : 4
return c
}

// Work-around <rdar://problem/17687851> by ensuring there is
// something that appears to be user code in unreachable blocks.
func userCode() {}
Expand Down