Skip to content

Commit ebc7432

Browse files
committed
Swift: implement imported_ and exported_modules
This has expanded the required builtin symbols.
1 parent 2e9d9cf commit ebc7432

File tree

9 files changed

+97
-15
lines changed

9 files changed

+97
-15
lines changed

swift/extractor/SwiftExtractor.cpp

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,68 @@ static void getBuiltinDecls(swift::ModuleDecl& builtinModule,
9090
llvm::SmallVector<swift::Decl*>& decls) {
9191
llvm::SmallVector<swift::ValueDecl*> values;
9292
for (auto symbol : {
93-
"zeroInitializer", "BridgeObject", "Word", "NativeObject",
94-
"RawPointer", "Int1", "Int8", "Int16",
95-
"Int32", "Int64", "IntLiteral", "FPIEEE16",
96-
"FPIEEE32", "FPIEEE64", "FPIEEE80", "Vec2xInt8",
97-
"Vec4xInt8", "Vec8xInt8", "Vec16xInt8", "Vec32xInt8",
98-
"Vec64xInt8", "Vec2xInt16", "Vec4xInt16", "Vec8xInt16",
99-
"Vec16xInt16", "Vec32xInt16", "Vec64xInt16", "Vec2xInt32",
100-
"Vec4xInt32", "Vec8xInt32", "Vec16xInt32", "Vec32xInt32",
101-
"Vec64xInt32", "Vec2xInt64", "Vec4xInt64", "Vec8xInt64",
102-
"Vec16xInt64", "Vec32xInt64", "Vec64xInt64", "Vec2xFPIEEE16",
103-
"Vec4xFPIEEE16", "Vec8xFPIEEE16", "Vec16xFPIEEE16", "Vec32xFPIEEE16",
104-
"Vec64xFPIEEE16", "Vec2xFPIEEE32", "Vec4xFPIEEE32", "Vec8xFPIEEE32",
105-
"Vec16xFPIEEE32", "Vec32xFPIEEE32", "Vec64xFPIEEE32", "Vec2xFPIEEE64",
106-
"Vec4xFPIEEE64", "Vec8xFPIEEE64", "Vec16xFPIEEE64", "Vec32xFPIEEE64",
93+
"zeroInitializer",
94+
"BridgeObject",
95+
"Word",
96+
"NativeObject",
97+
"RawPointer",
98+
"Executor",
99+
"Job",
100+
"RawUnsafeContinuation",
101+
"addressof",
102+
"initialize",
103+
"reinterpretCast",
104+
"Int1",
105+
"Int8",
106+
"Int16",
107+
"Int32",
108+
"Int64",
109+
"IntLiteral",
110+
"FPIEEE16",
111+
"FPIEEE32",
112+
"FPIEEE64",
113+
"FPIEEE80",
114+
"Vec2xInt8",
115+
"Vec4xInt8",
116+
"Vec8xInt8",
117+
"Vec16xInt8",
118+
"Vec32xInt8",
119+
"Vec64xInt8",
120+
"Vec2xInt16",
121+
"Vec4xInt16",
122+
"Vec8xInt16",
123+
"Vec16xInt16",
124+
"Vec32xInt16",
125+
"Vec64xInt16",
126+
"Vec2xInt32",
127+
"Vec4xInt32",
128+
"Vec8xInt32",
129+
"Vec16xInt32",
130+
"Vec32xInt32",
131+
"Vec64xInt32",
132+
"Vec2xInt64",
133+
"Vec4xInt64",
134+
"Vec8xInt64",
135+
"Vec16xInt64",
136+
"Vec32xInt64",
137+
"Vec64xInt64",
138+
"Vec2xFPIEEE16",
139+
"Vec4xFPIEEE16",
140+
"Vec8xFPIEEE16",
141+
"Vec16xFPIEEE16",
142+
"Vec32xFPIEEE16",
143+
"Vec64xFPIEEE16",
144+
"Vec2xFPIEEE32",
145+
"Vec4xFPIEEE32",
146+
"Vec8xFPIEEE32",
147+
"Vec16xFPIEEE32",
148+
"Vec32xFPIEEE32",
149+
"Vec64xFPIEEE32",
150+
"Vec2xFPIEEE64",
151+
"Vec4xFPIEEE64",
152+
"Vec8xFPIEEE64",
153+
"Vec16xFPIEEE64",
154+
"Vec32xFPIEEE64",
107155
"Vec64xFPIEEE64",
108156
}) {
109157
builtinModule.lookupValue(builtinModule.getASTContext().getIdentifier(symbol),

swift/extractor/visitors/DeclVisitor.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,17 @@ std::optional<codeql::ModuleDecl> DeclVisitor::translateModuleDecl(const swift::
264264
}
265265
entry->is_builtin_module = decl.isBuiltinModule();
266266
entry->is_system_module = decl.isSystemModule();
267+
using K = swift::ModuleDecl::ImportFilterKind;
268+
llvm::SmallVector<swift::ImportedModule> imports;
269+
decl.getImportedModules(imports, K::Default);
270+
for (const auto& import : imports) {
271+
entry->imported_modules.push_back(dispatcher_.fetchLabel(import.importedModule));
272+
}
273+
imports.clear();
274+
decl.getImportedModules(imports, K::Exported);
275+
for (const auto& import : imports) {
276+
entry->exported_modules.push_back(dispatcher_.fetchLabel(import.importedModule));
277+
}
267278
fillTypeDecl(decl, *entry);
268279
return entry;
269280
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
| file://:0:0:0:0 | Foo | getModule: | file://:0:0:0:0 | Foo | getInterfaceType: | module<Foo> | getName: | Foo | isBuiltinModule: | no | isSystemModule: | no |
2+
| file://:0:0:0:0 | __ObjC | getModule: | file://:0:0:0:0 | __ObjC | getInterfaceType: | module<__ObjC> | getName: | __ObjC | isBuiltinModule: | no | isSystemModule: | no |
23
| file://:0:0:0:0 | default_module_name | getModule: | file://:0:0:0:0 | default_module_name | getInterfaceType: | module<default_module_name> | getName: | default_module_name | isBuiltinModule: | no | isSystemModule: | no |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
| file://:0:0:0:0 | Foo | 0 | file://:0:0:0:0 | Swift |
2+
| file://:0:0:0:0 | Foo | 1 | file://:0:0:0:0 | _Concurrency |
3+
| file://:0:0:0:0 | Foo | 2 | file://:0:0:0:0 | SwiftOnoneSupport |
4+
| file://:0:0:0:0 | __ObjC | 0 | file://:0:0:0:0 | Swift |
5+
| file://:0:0:0:0 | default_module_name | 0 | file://:0:0:0:0 | Swift |
6+
| file://:0:0:0:0 | default_module_name | 1 | file://:0:0:0:0 | _Concurrency |
7+
| file://:0:0:0:0 | default_module_name | 2 | file://:0:0:0:0 | SwiftOnoneSupport |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| file://:0:0:0:0 | Foo | 0 | file://:0:0:0:0 | Swift |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
| file://:0:0:0:0 | Foo | 0 | file://:0:0:0:0 | Swift |
2+
| file://:0:0:0:0 | Foo | 1 | file://:0:0:0:0 | _Concurrency |
3+
| file://:0:0:0:0 | Foo | 2 | file://:0:0:0:0 | SwiftOnoneSupport |
4+
| file://:0:0:0:0 | __ObjC | 0 | file://:0:0:0:0 | Swift |
5+
| file://:0:0:0:0 | default_module_name | 0 | file://:0:0:0:0 | Swift |
6+
| file://:0:0:0:0 | default_module_name | 1 | file://:0:0:0:0 | _Concurrency |
7+
| file://:0:0:0:0 | default_module_name | 2 | file://:0:0:0:0 | SwiftOnoneSupport |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
//codeql-extractor-options: -module-name Foo
2+
@_exported import Swift
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
| Builtin.BridgeObject | getName: | Builtin.BridgeObject | getCanonicalType: | Builtin.BridgeObject |
2+
| Builtin.Executor | getName: | Builtin.Executor | getCanonicalType: | Builtin.Executor |
23
| Builtin.FPIEEE32 | getName: | Builtin.FPIEEE32 | getCanonicalType: | Builtin.FPIEEE32 |
34
| Builtin.FPIEEE64 | getName: | Builtin.FPIEEE64 | getCanonicalType: | Builtin.FPIEEE64 |
45
| Builtin.IntLiteral | getName: | Builtin.IntLiteral | getCanonicalType: | Builtin.IntLiteral |
6+
| Builtin.Job | getName: | Builtin.Job | getCanonicalType: | Builtin.Job |
57
| Builtin.NativeObject | getName: | Builtin.NativeObject | getCanonicalType: | Builtin.NativeObject |
68
| Builtin.RawPointer | getName: | Builtin.RawPointer | getCanonicalType: | Builtin.RawPointer |
9+
| Builtin.RawUnsafeContinuation | getName: | Builtin.RawUnsafeContinuation | getCanonicalType: | Builtin.RawUnsafeContinuation |

swift/ql/test/extractor-tests/generated/type/BuiltinType/builtin_types.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ func foo(
55
_: Builtin.FPIEEE64,
66
_: Builtin.BridgeObject,
77
_: Builtin.NativeObject,
8-
_: Builtin.RawPointer
8+
_: Builtin.RawPointer,
9+
_: Builtin.Executor,
10+
_: Builtin.Job,
11+
_: Builtin.RawUnsafeContinuation
912
) {}

0 commit comments

Comments
 (0)