Skip to content

Commit c42add2

Browse files
committed
Swift: Add test cases for overflow and pointwise binary arithmetic operations.
1 parent 8e069b7 commit c42add2

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

swift/ql/test/library-tests/elements/expr/arithmeticoperation/arithmeticoperation.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ func test(c: Bool, x: Int, y: Int, z: Int) {
1010
v = x % y;
1111
v = -x;
1212
v = +x;
13+
14+
// arithmetic operations with overflow
15+
v = x &+ y; // NOT DETECTED
16+
v = x &- y; // NOT DETECTED
17+
v = x &* y; // NOT DETECTED
1318
}

swift/ql/test/library-tests/elements/expr/bitwiseopration/bitwiseoperation.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,16 @@ func bitwise() {
55
_ = 1 ^ 2
66
_ = 1 << 0
77
_ = 1 >> 0
8+
9+
// bitwise operations with overflow
10+
_ = 1 &<< 1 // NOT DETECTED
11+
_ = 1 &>> 1 // NOT DETECTED
12+
13+
// pointwise bitwise operations
14+
let a = SIMD4<Int>(1, 2, 3, 4)
15+
let b = SIMD4<Int>(4, 3, 2, 1)
16+
let m = a .< b
17+
_ = m .& m // NOT DETECTED
18+
_ = m .| m // NOT DETECTED
19+
_ = m .^ m // NOT DETECTED
820
}

0 commit comments

Comments
 (0)