Swift: implement imported_ and exported_modules

This has expanded the required builtin symbols.
This commit is contained in:
Paolo Tranquilli
2022-08-26 11:21:57 +02:00
parent 2e9d9cfb20
commit ebc7432f46
9 changed files with 97 additions and 15 deletions

View File

@@ -90,20 +90,68 @@ static void getBuiltinDecls(swift::ModuleDecl& builtinModule,
llvm::SmallVector<swift::Decl*>& decls) {
llvm::SmallVector<swift::ValueDecl*> values;
for (auto symbol : {
"zeroInitializer", "BridgeObject", "Word", "NativeObject",
"RawPointer", "Int1", "Int8", "Int16",
"Int32", "Int64", "IntLiteral", "FPIEEE16",
"FPIEEE32", "FPIEEE64", "FPIEEE80", "Vec2xInt8",
"Vec4xInt8", "Vec8xInt8", "Vec16xInt8", "Vec32xInt8",
"Vec64xInt8", "Vec2xInt16", "Vec4xInt16", "Vec8xInt16",
"Vec16xInt16", "Vec32xInt16", "Vec64xInt16", "Vec2xInt32",
"Vec4xInt32", "Vec8xInt32", "Vec16xInt32", "Vec32xInt32",
"Vec64xInt32", "Vec2xInt64", "Vec4xInt64", "Vec8xInt64",
"Vec16xInt64", "Vec32xInt64", "Vec64xInt64", "Vec2xFPIEEE16",
"Vec4xFPIEEE16", "Vec8xFPIEEE16", "Vec16xFPIEEE16", "Vec32xFPIEEE16",
"Vec64xFPIEEE16", "Vec2xFPIEEE32", "Vec4xFPIEEE32", "Vec8xFPIEEE32",
"Vec16xFPIEEE32", "Vec32xFPIEEE32", "Vec64xFPIEEE32", "Vec2xFPIEEE64",
"Vec4xFPIEEE64", "Vec8xFPIEEE64", "Vec16xFPIEEE64", "Vec32xFPIEEE64",
"zeroInitializer",
"BridgeObject",
"Word",
"NativeObject",
"RawPointer",
"Executor",
"Job",
"RawUnsafeContinuation",
"addressof",
"initialize",
"reinterpretCast",
"Int1",
"Int8",
"Int16",
"Int32",
"Int64",
"IntLiteral",
"FPIEEE16",
"FPIEEE32",
"FPIEEE64",
"FPIEEE80",
"Vec2xInt8",
"Vec4xInt8",
"Vec8xInt8",
"Vec16xInt8",
"Vec32xInt8",
"Vec64xInt8",
"Vec2xInt16",
"Vec4xInt16",
"Vec8xInt16",
"Vec16xInt16",
"Vec32xInt16",
"Vec64xInt16",
"Vec2xInt32",
"Vec4xInt32",
"Vec8xInt32",
"Vec16xInt32",
"Vec32xInt32",
"Vec64xInt32",
"Vec2xInt64",
"Vec4xInt64",
"Vec8xInt64",
"Vec16xInt64",
"Vec32xInt64",
"Vec64xInt64",
"Vec2xFPIEEE16",
"Vec4xFPIEEE16",
"Vec8xFPIEEE16",
"Vec16xFPIEEE16",
"Vec32xFPIEEE16",
"Vec64xFPIEEE16",
"Vec2xFPIEEE32",
"Vec4xFPIEEE32",
"Vec8xFPIEEE32",
"Vec16xFPIEEE32",
"Vec32xFPIEEE32",
"Vec64xFPIEEE32",
"Vec2xFPIEEE64",
"Vec4xFPIEEE64",
"Vec8xFPIEEE64",
"Vec16xFPIEEE64",
"Vec32xFPIEEE64",
"Vec64xFPIEEE64",
}) {
builtinModule.lookupValue(builtinModule.getASTContext().getIdentifier(symbol),

View File

@@ -264,6 +264,17 @@ std::optional<codeql::ModuleDecl> DeclVisitor::translateModuleDecl(const swift::
}
entry->is_builtin_module = decl.isBuiltinModule();
entry->is_system_module = decl.isSystemModule();
using K = swift::ModuleDecl::ImportFilterKind;
llvm::SmallVector<swift::ImportedModule> imports;
decl.getImportedModules(imports, K::Default);
for (const auto& import : imports) {
entry->imported_modules.push_back(dispatcher_.fetchLabel(import.importedModule));
}
imports.clear();
decl.getImportedModules(imports, K::Exported);
for (const auto& import : imports) {
entry->exported_modules.push_back(dispatcher_.fetchLabel(import.importedModule));
}
fillTypeDecl(decl, *entry);
return entry;
}

View File

@@ -1,2 +1,3 @@
| file://:0:0:0:0 | Foo | getModule: | file://:0:0:0:0 | Foo | getInterfaceType: | module<Foo> | getName: | Foo | isBuiltinModule: | no | isSystemModule: | no |
| file://:0:0:0:0 | __ObjC | getModule: | file://:0:0:0:0 | __ObjC | getInterfaceType: | module<__ObjC> | getName: | __ObjC | isBuiltinModule: | no | isSystemModule: | no |
| 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 |

View File

@@ -0,0 +1,7 @@
| file://:0:0:0:0 | Foo | 0 | file://:0:0:0:0 | Swift |
| file://:0:0:0:0 | Foo | 1 | file://:0:0:0:0 | _Concurrency |
| file://:0:0:0:0 | Foo | 2 | file://:0:0:0:0 | SwiftOnoneSupport |
| file://:0:0:0:0 | __ObjC | 0 | file://:0:0:0:0 | Swift |
| file://:0:0:0:0 | default_module_name | 0 | file://:0:0:0:0 | Swift |
| file://:0:0:0:0 | default_module_name | 1 | file://:0:0:0:0 | _Concurrency |
| file://:0:0:0:0 | default_module_name | 2 | file://:0:0:0:0 | SwiftOnoneSupport |

View File

@@ -0,0 +1 @@
| file://:0:0:0:0 | Foo | 0 | file://:0:0:0:0 | Swift |

View File

@@ -0,0 +1,7 @@
| file://:0:0:0:0 | Foo | 0 | file://:0:0:0:0 | Swift |
| file://:0:0:0:0 | Foo | 1 | file://:0:0:0:0 | _Concurrency |
| file://:0:0:0:0 | Foo | 2 | file://:0:0:0:0 | SwiftOnoneSupport |
| file://:0:0:0:0 | __ObjC | 0 | file://:0:0:0:0 | Swift |
| file://:0:0:0:0 | default_module_name | 0 | file://:0:0:0:0 | Swift |
| file://:0:0:0:0 | default_module_name | 1 | file://:0:0:0:0 | _Concurrency |
| file://:0:0:0:0 | default_module_name | 2 | file://:0:0:0:0 | SwiftOnoneSupport |

View File

@@ -1 +1,2 @@
//codeql-extractor-options: -module-name Foo
@_exported import Swift

View File

@@ -1,6 +1,9 @@
| Builtin.BridgeObject | getName: | Builtin.BridgeObject | getCanonicalType: | Builtin.BridgeObject |
| Builtin.Executor | getName: | Builtin.Executor | getCanonicalType: | Builtin.Executor |
| Builtin.FPIEEE32 | getName: | Builtin.FPIEEE32 | getCanonicalType: | Builtin.FPIEEE32 |
| Builtin.FPIEEE64 | getName: | Builtin.FPIEEE64 | getCanonicalType: | Builtin.FPIEEE64 |
| Builtin.IntLiteral | getName: | Builtin.IntLiteral | getCanonicalType: | Builtin.IntLiteral |
| Builtin.Job | getName: | Builtin.Job | getCanonicalType: | Builtin.Job |
| Builtin.NativeObject | getName: | Builtin.NativeObject | getCanonicalType: | Builtin.NativeObject |
| Builtin.RawPointer | getName: | Builtin.RawPointer | getCanonicalType: | Builtin.RawPointer |
| Builtin.RawUnsafeContinuation | getName: | Builtin.RawUnsafeContinuation | getCanonicalType: | Builtin.RawUnsafeContinuation |

View File

@@ -5,5 +5,8 @@ func foo(
_: Builtin.FPIEEE64,
_: Builtin.BridgeObject,
_: Builtin.NativeObject,
_: Builtin.RawPointer
_: Builtin.RawPointer,
_: Builtin.Executor,
_: Builtin.Job,
_: Builtin.RawUnsafeContinuation
) {}