Skip to content

Commit 589e0af

Browse files
committed
Swift: Test for pointer types.
1 parent 9423c21 commit 589e0af

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
class MyClass {
3+
init() {
4+
val = 0
5+
}
6+
7+
var val: Int
8+
}
9+
10+
func test() {
11+
var p1: UnsafePointer<Int>
12+
var p2: UnsafeMutablePointer<UInt8>
13+
var p3: UnsafeBufferPointer<String>
14+
var p4: UnsafeMutableBufferPointer<MyClass>
15+
var p5: UnsafeRawPointer
16+
var p6: UnsafeMutableRawPointer
17+
var p7: UnsafeRawBufferPointer
18+
var p8: UnsafeMutableRawBufferPointer
19+
20+
var op: OpaquePointer // C-interop
21+
var aump: AutoreleasingUnsafeMutablePointer<UInt8> // ObjC-interop
22+
var um: Unmanaged<MyClass> // C-interop
23+
var cvlp: CVaListPointer // varargs list pointer
24+
25+
var mbp: ManagedBufferPointer<Int, MyClass>
26+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
| pointers.swift:11:6:11:6 | p1 | UnsafePointer<Int> | UnsafeTypedPointerType |
2+
| pointers.swift:12:6:12:6 | p2 | UnsafeMutablePointer<UInt8> | UnsafeTypedPointerType |
3+
| pointers.swift:13:6:13:6 | p3 | UnsafeBufferPointer<String> | UnsafeTypedPointerType |
4+
| pointers.swift:14:6:14:6 | p4 | UnsafeMutableBufferPointer<MyClass> | UnsafeTypedPointerType |
5+
| pointers.swift:15:6:15:6 | p5 | UnsafeRawPointer | UnsafeRawPointerType |
6+
| pointers.swift:16:6:16:6 | p6 | UnsafeMutableRawPointer | UnsafeRawPointerType |
7+
| pointers.swift:17:6:17:6 | p7 | UnsafeRawBufferPointer | UnsafeRawPointerType |
8+
| pointers.swift:18:6:18:6 | p8 | UnsafeMutableRawBufferPointer | UnsafeRawPointerType |
9+
| pointers.swift:20:6:20:6 | op | OpaquePointer | OpaquePointerType |
10+
| pointers.swift:21:6:21:6 | aump | AutoreleasingUnsafeMutablePointer<UInt8> | AutoreleasingUnsafeMutablePointerType |
11+
| pointers.swift:22:6:22:6 | um | Unmanaged<MyClass> | UnmanagedType |
12+
| pointers.swift:23:6:23:6 | cvlp | CVaListPointer | CVaListPointerType |
13+
| pointers.swift:25:6:25:6 | mbp | ManagedBufferPointer<Int, MyClass> | ManagedBufferPointerType |
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import swift
2+
import codeql.swift.frameworks.StandardLibrary.PointerTypes
3+
4+
string describe(Type t) {
5+
t instanceof BuiltinRawPointerType and result = "BuiltinRawPointerType"
6+
or
7+
t instanceof UnsafeTypedPointerType and result = "UnsafeTypedPointerType"
8+
or
9+
t instanceof UnsafeRawPointerType and result = "UnsafeRawPointerType"
10+
or
11+
t instanceof OpaquePointerType and result = "OpaquePointerType"
12+
or
13+
t instanceof AutoreleasingUnsafeMutablePointerType and result = "AutoreleasingUnsafeMutablePointerType"
14+
or
15+
t instanceof UnmanagedType and result = "UnmanagedType"
16+
or
17+
t instanceof CVaListPointerType and result = "CVaListPointerType"
18+
or
19+
t instanceof ManagedBufferPointerType and result = "ManagedBufferPointerType"
20+
}
21+
22+
from VarDecl v, Type t
23+
where
24+
v.getLocation().getFile().getBaseName() != "" and
25+
t = v.getType()
26+
select v, t.toString(), strictconcat(describe(t), ", ")

0 commit comments

Comments
 (0)