forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Exclusivity] Put suppression for free function swap() behind a flag
And leave suppression off by default for now. We'll use this to evaluate how often swap() causes exclusivity conflicts to be reported.
- Loading branch information
1 parent
6d35d32
commit ae3b13e
Showing
6 changed files
with
52 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// RUN: %target-swift-frontend -enforce-exclusivity=checked -suppress-static-exclusivity-swap -emit-sil -primary-file %s -o /dev/null -verify | ||
|
||
import Swift | ||
|
||
func takesTwoInouts(_ p1: inout Int, _ p2: inout Int) { } | ||
|
||
func swapSuppression(_ i: Int, _ j: Int) { | ||
var a: [Int] = [1, 2, 3] | ||
|
||
swap(&a[i], &a[j]) // no-warning | ||
|
||
// expected-warning@+2{{modification requires exclusive access}} | ||
// expected-note@+1{{conflicting modification requires exclusive access}} | ||
takesTwoInouts(&a[i], &a[j]) | ||
} | ||
|
||
func missedSwapSuppression(_ i: Int, _ j: Int) { | ||
var a: [Int] = [1, 2, 3] | ||
|
||
// We don't suppress when swap() is used as a value | ||
let mySwap: (inout Int, inout Int) -> () = swap | ||
|
||
// expected-warning@+2{{modification requires exclusive access}} | ||
// expected-note@+1{{conflicting modification requires exclusive access}} | ||
mySwap(&a[i], &a[j]) | ||
} | ||
|
||
func dontSuppressUserSwap(_ i: Int, _ j: Int) { | ||
var a: [Int] = [1, 2, 3] | ||
|
||
// Don't suppress on user-defined swap. | ||
func swap<T>(_ p1: inout T, _ p2: inout T) { | ||
return (p1, p2) = (p2, p1) | ||
} | ||
|
||
// expected-warning@+2{{modification requires exclusive access}} | ||
// expected-note@+1{{conflicting modification requires exclusive access}} | ||
swap(&a[i], &a[j]) | ||
} |