Skip to content

Commit 3249cee

Browse files
committed
Swift: Add an overall PointerType.
1 parent 589e0af commit 3249cee

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

swift/ql/lib/codeql/swift/frameworks/StandardLibrary/PointerTypes.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@
55

66
import swift
77

8+
/**
9+
* A type that is used as a pointer in Swift, such as `UnsafePointer`,
10+
* `UnsafeBufferPointer` and similar types.
11+
*/
12+
class PointerType extends Type {
13+
PointerType() {
14+
this instanceof UnsafeTypedPointerType or
15+
this instanceof UnsafeRawPointerType or
16+
this instanceof OpaquePointerType or
17+
this instanceof AutoreleasingUnsafeMutablePointerType or
18+
this instanceof UnmanagedType or
19+
this instanceof CVaListPointerType or
20+
this instanceof ManagedBufferPointerType
21+
}
22+
}
23+
824
/**
925
* A Swift unsafe typed pointer type such as `UnsafePointer`,
1026
* `UnsafeMutablePointer` or `UnsafeBufferPointer`.
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +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 |
1+
| pointers.swift:11:6:11:6 | p1 | UnsafePointer<Int> | PointerType, UnsafeTypedPointerType |
2+
| pointers.swift:12:6:12:6 | p2 | UnsafeMutablePointer<UInt8> | PointerType, UnsafeTypedPointerType |
3+
| pointers.swift:13:6:13:6 | p3 | UnsafeBufferPointer<String> | PointerType, UnsafeTypedPointerType |
4+
| pointers.swift:14:6:14:6 | p4 | UnsafeMutableBufferPointer<MyClass> | PointerType, UnsafeTypedPointerType |
5+
| pointers.swift:15:6:15:6 | p5 | UnsafeRawPointer | PointerType, UnsafeRawPointerType |
6+
| pointers.swift:16:6:16:6 | p6 | UnsafeMutableRawPointer | PointerType, UnsafeRawPointerType |
7+
| pointers.swift:17:6:17:6 | p7 | UnsafeRawBufferPointer | PointerType, UnsafeRawPointerType |
8+
| pointers.swift:18:6:18:6 | p8 | UnsafeMutableRawBufferPointer | PointerType, UnsafeRawPointerType |
9+
| pointers.swift:20:6:20:6 | op | OpaquePointer | OpaquePointerType, PointerType |
10+
| pointers.swift:21:6:21:6 | aump | AutoreleasingUnsafeMutablePointer<UInt8> | AutoreleasingUnsafeMutablePointerType, PointerType |
11+
| pointers.swift:22:6:22:6 | um | Unmanaged<MyClass> | PointerType, UnmanagedType |
12+
| pointers.swift:23:6:23:6 | cvlp | CVaListPointer | CVaListPointerType, PointerType |
13+
| pointers.swift:25:6:25:6 | mbp | ManagedBufferPointer<Int, MyClass> | ManagedBufferPointerType, PointerType |

swift/ql/test/library-tests/elements/type/pointertypes/pointertypes.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import swift
22
import codeql.swift.frameworks.StandardLibrary.PointerTypes
33

44
string describe(Type t) {
5+
t instanceof PointerType and result = "PointerType"
6+
or
57
t instanceof BuiltinRawPointerType and result = "BuiltinRawPointerType"
68
or
79
t instanceof UnsafeTypedPointerType and result = "UnsafeTypedPointerType"

0 commit comments

Comments
 (0)