mirror of
https://github.com/github/codeql.git
synced 2026-05-05 13:45:19 +02:00
Swift: Add a test for assignment exprs.
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
| assignment.swift:6:2:6:6 | ... = ... | AssignExpr | x | 1 |
|
||||
| assignment.swift:33:2:33:6 | ... = ... | AssignExpr | y | z |
|
||||
@@ -0,0 +1,14 @@
|
||||
import swift
|
||||
|
||||
string describe(Expr e) {
|
||||
e instanceof AssignExpr and result = "AssignExpr"
|
||||
}
|
||||
|
||||
from AssignExpr e
|
||||
where
|
||||
e.getLocation().getFile().getBaseName() != ""
|
||||
select
|
||||
e,
|
||||
concat(describe(e), ", "),
|
||||
concat(e.getDest().toString(), ", "),
|
||||
concat(e.getSource().toString(), ", ")
|
||||
@@ -0,0 +1,37 @@
|
||||
|
||||
func test() {
|
||||
var x = 0
|
||||
|
||||
// simple assignment
|
||||
x = 1
|
||||
|
||||
// arithmetic assignment operations
|
||||
x += 1
|
||||
x -= 1
|
||||
x *= 1
|
||||
x /= 1
|
||||
x %= 1
|
||||
|
||||
// bitwise assignment operations
|
||||
x &= 1
|
||||
x |= 1
|
||||
x ^= 1
|
||||
x <<= 1
|
||||
x >>= 1
|
||||
|
||||
// assignment operations with overflow
|
||||
x &*= 1
|
||||
x &+= 1
|
||||
x &-= 1
|
||||
x &<<= 1
|
||||
x &>>= 1
|
||||
|
||||
// pointwise assignment operations
|
||||
var y = SIMD4<Int>(1, 2, 3, 4)
|
||||
let z = SIMD4<Int>(5, 6, 7, 8)
|
||||
var m = y .< z
|
||||
y = z
|
||||
m .&= m
|
||||
m .|= m
|
||||
m .^= m
|
||||
}
|
||||
Reference in New Issue
Block a user