Skip to content

Commit decd5c1

Browse files
authored
Merge pull request github#12508 from github/redsun82/swift-deduplication-test
Swift: add an initial draft for a deduplication test
2 parents de1ecf9 + 91ce88e commit decd5c1

File tree

12 files changed

+136
-0
lines changed

12 files changed

+136
-0
lines changed

swift/extractor/mangler/SwiftMangler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <swift/AST/ASTMangler.h>
44
#include <swift/AST/Types.h>
55

6+
#include <optional>
7+
68
namespace codeql {
79
class SwiftMangler {
810
public:
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
| Builtin.BridgeObject | BuiltinBridgeObjectType |
2+
| Builtin.Executor | BuiltinExecutorType |
3+
| Builtin.FPIEEE32 | BuiltinFloatType |
4+
| Builtin.FPIEEE64 | BuiltinFloatType |
5+
| Builtin.FPIEEE80 | BuiltinFloatType |
6+
| Builtin.Int1 | BuiltinIntegerType |
7+
| Builtin.Int8 | BuiltinIntegerType |
8+
| Builtin.Int16 | BuiltinIntegerType |
9+
| Builtin.Int32 | BuiltinIntegerType |
10+
| Builtin.Int64 | BuiltinIntegerType |
11+
| Builtin.IntLiteral | BuiltinIntegerLiteralType |
12+
| Builtin.Job | BuiltinJobType |
13+
| Builtin.NativeObject | BuiltinNativeObjectType |
14+
| Builtin.RawPointer | BuiltinRawPointerType |
15+
| Builtin.RawUnsafeContinuation | BuiltinRawUnsafeContinuationType |
16+
| Builtin.Vec2xFPIEEE32 | BuiltinVectorType |
17+
| Builtin.Vec2xFPIEEE64 | BuiltinVectorType |
18+
| Builtin.Vec2xInt8 | BuiltinVectorType |
19+
| Builtin.Vec2xInt16 | BuiltinVectorType |
20+
| Builtin.Vec2xInt32 | BuiltinVectorType |
21+
| Builtin.Vec2xInt64 | BuiltinVectorType |
22+
| Builtin.Vec4xFPIEEE32 | BuiltinVectorType |
23+
| Builtin.Vec4xFPIEEE64 | BuiltinVectorType |
24+
| Builtin.Vec4xInt8 | BuiltinVectorType |
25+
| Builtin.Vec4xInt16 | BuiltinVectorType |
26+
| Builtin.Vec4xInt32 | BuiltinVectorType |
27+
| Builtin.Vec4xInt64 | BuiltinVectorType |
28+
| Builtin.Vec8xFPIEEE32 | BuiltinVectorType |
29+
| Builtin.Vec8xFPIEEE64 | BuiltinVectorType |
30+
| Builtin.Vec8xInt8 | BuiltinVectorType |
31+
| Builtin.Vec8xInt16 | BuiltinVectorType |
32+
| Builtin.Vec8xInt32 | BuiltinVectorType |
33+
| Builtin.Vec8xInt64 | BuiltinVectorType |
34+
| Builtin.Vec16xFPIEEE32 | BuiltinVectorType |
35+
| Builtin.Vec16xFPIEEE64 | BuiltinVectorType |
36+
| Builtin.Vec16xInt8 | BuiltinVectorType |
37+
| Builtin.Vec16xInt16 | BuiltinVectorType |
38+
| Builtin.Vec16xInt32 | BuiltinVectorType |
39+
| Builtin.Vec16xInt64 | BuiltinVectorType |
40+
| Builtin.Vec32xFPIEEE32 | BuiltinVectorType |
41+
| Builtin.Vec32xFPIEEE64 | BuiltinVectorType |
42+
| Builtin.Vec32xInt8 | BuiltinVectorType |
43+
| Builtin.Vec32xInt16 | BuiltinVectorType |
44+
| Builtin.Vec32xInt32 | BuiltinVectorType |
45+
| Builtin.Vec32xInt64 | BuiltinVectorType |
46+
| Builtin.Vec64xFPIEEE32 | BuiltinVectorType |
47+
| Builtin.Vec64xFPIEEE64 | BuiltinVectorType |
48+
| Builtin.Vec64xInt8 | BuiltinVectorType |
49+
| Builtin.Vec64xInt16 | BuiltinVectorType |
50+
| Builtin.Vec64xInt32 | BuiltinVectorType |
51+
| Builtin.Vec64xInt64 | BuiltinVectorType |
52+
| Builtin.Word | BuiltinIntegerType |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import swift
2+
3+
from BuiltinType t
4+
// FPIEEE16 related stuff is not there on macOS
5+
where not t.toString().matches("%FPIEEE16")
6+
select t, t.getPrimaryQlClasses()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
| Sources/deduplication/def.swift:1:1:1:9 | var ... = ... | PatternBindingDecl |
2+
| Sources/deduplication/def.swift:1:5:1:5 | x | ConcreteVarDecl |
3+
| Sources/deduplication/def.swift:3:1:3:20 | Generic | StructDecl |
4+
| Sources/deduplication/def.swift:3:8:3:8 | Generic<T>.init() | ConstructorDecl |
5+
| Sources/deduplication/def.swift:3:8:3:8 | self | ParamDecl |
6+
| Sources/deduplication/def.swift:3:16:3:16 | T | GenericTypeParamDecl |
7+
| Sources/deduplication/def.swift:5:1:5:41 | var ... = ... | PatternBindingDecl |
8+
| Sources/deduplication/def.swift:5:5:5:5 | instantiated_generic | ConcreteVarDecl |
9+
| Sources/deduplication/def.swift:7:1:7:42 | function(_:) | ConcreteFuncDecl |
10+
| Sources/deduplication/def.swift:7:15:7:18 | _ | ParamDecl |
11+
| Sources/deduplication/use.swift:1:1:1:13 | var ... = ... | PatternBindingDecl |
12+
| Sources/deduplication/use.swift:1:5:1:5 | use_x | ConcreteVarDecl |
13+
| Sources/deduplication/use.swift:2:1:2:32 | var ... = ... | PatternBindingDecl |
14+
| Sources/deduplication/use.swift:2:5:2:5 | use_instantiated_generic | ConcreteVarDecl |
15+
| Sources/deduplication/use.swift:3:1:3:20 | var ... = ... | PatternBindingDecl |
16+
| Sources/deduplication/use.swift:3:5:3:5 | use_function | ConcreteVarDecl |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import swift
2+
import Relevant
3+
4+
from Decl d
5+
where relevant(d)
6+
select d, d.getPrimaryQlClasses()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// swift-tools-version: 5.5
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "deduplication",
8+
products: [
9+
.library(
10+
name: "deduplication",
11+
targets: ["deduplication"]),
12+
],
13+
targets: [
14+
.target(name: "deduplication")
15+
]
16+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import swift
2+
3+
predicate relevant(Locatable loc) {
4+
loc.getLocation().getFile().getName().matches("%/swift/integration-tests/%/Sources/%")
5+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var x = 42
2+
3+
struct Generic<T> {}
4+
5+
var instantiated_generic = Generic<Int>()
6+
7+
func function(_: Int) -> Int { return 42 }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
let use_x = x
2+
let use_instantiated_generic = instantiated_generic
3+
let use_function = function
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
| (Int) -> Int | FunctionType | function(_:) |
2+
| (Int) -> Int | FunctionType | use_function |
3+
| <T> (Generic<T>.Type) -> () -> Generic<T> | GenericFunctionType | Generic<T>.init() |
4+
| Generic<Int> | BoundGenericStructType | instantiated_generic |
5+
| Generic<Int> | BoundGenericStructType | use_instantiated_generic |
6+
| Generic<T> | BoundGenericStructType | self |
7+
| Generic<T>.Type | MetatypeType | Generic |
8+
| Int | StructType | _, x |
9+
| Int | StructType | use_x |
10+
| T.Type | MetatypeType | T |

0 commit comments

Comments
 (0)