mirror of
https://github.com/github/codeql.git
synced 2026-04-25 00:35:20 +02:00
Swift: mangle builtin and tuple types
This commit is contained in:
@@ -42,9 +42,9 @@ SwiftMangledName SwiftMangler::mangleDecl(const swift::Decl& decl) {
|
||||
return {};
|
||||
}
|
||||
|
||||
// we do not deduplicate GenericTypeParamDecl, as their mangling is ambiguous in the presence of
|
||||
// extensions
|
||||
if (decl.getKind() == swift::DeclKind::GenericTypeParam) {
|
||||
// we do not deduplicate GenericTypeParamDecl of extensions yet, as their mangling is ambiguous
|
||||
if (decl.getKind() == swift::DeclKind::GenericTypeParam &&
|
||||
decl.getDeclContext()->getContextKind() == swift::DeclContextKind::ExtensionDecl) {
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -81,9 +81,21 @@ SwiftMangledName SwiftMangler::visitModuleType(const swift::ModuleType* type) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
SwiftMangledName SwiftMangler::visitTupleType(const swift::TupleType* type) {
|
||||
auto ret = initMangled(type);
|
||||
for (const auto& element : type->getElements()) {
|
||||
if (element.hasName()) {
|
||||
ret << element.getName().str();
|
||||
}
|
||||
ret << dispatcher.fetchLabel(element.getType());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
SwiftMangledName SwiftMangler::visitBuiltinType(const swift::BuiltinType* type) {
|
||||
auto ret = initMangled(type);
|
||||
llvm::SmallString<32> buffer;
|
||||
ret << type->getTypeName(buffer, /* prependBuiltinNamespace= */ false);
|
||||
ret << buffer.str();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,8 @@ class SwiftMangler : private swift::TypeVisitor<SwiftMangler, SwiftMangledName>
|
||||
static SwiftMangledName visitType(const swift::TypeBase* type) { return {}; }
|
||||
|
||||
SwiftMangledName visitModuleType(const swift::ModuleType* type);
|
||||
SwiftMangledName visitTupleType(const swift::TupleType* type);
|
||||
SwiftMangledName visitBuiltinType(const swift::BuiltinType* type);
|
||||
|
||||
SwiftMangledName visitBuiltinType(const swift::BuiltinType* type);
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
//codeql-extractor-options: -parse-stdlib
|
||||
func foo(
|
||||
_: Builtin.IntLiteral,
|
||||
_: Builtin.FPIEEE32,
|
||||
_: Builtin.FPIEEE64,
|
||||
_: Builtin.BridgeObject,
|
||||
_: Builtin.NativeObject,
|
||||
_: Builtin.RawPointer,
|
||||
_: Builtin.Executor,
|
||||
_: Builtin.Job,
|
||||
_: Builtin.RawUnsafeContinuation
|
||||
) {}
|
||||
@@ -1,5 +1,6 @@
|
||||
| (Builtin.IntLiteral, Builtin.IntLiteral) | getName: | (Builtin.IntLiteral, Builtin.IntLiteral) | getCanonicalType: | (Builtin.IntLiteral, Builtin.IntLiteral) | getNumberOfTypes: | 2 |
|
||||
| (Builtin.IntLiteral, Builtin.IntLiteral) | getName: | (Builtin.IntLiteral, Builtin.IntLiteral) | getCanonicalType: | (Builtin.IntLiteral, Builtin.IntLiteral) | getNumberOfTypes: | 2 |
|
||||
| (Builtin.IntLiteral, Builtin.IntLiteral) | getName: | (Builtin.IntLiteral, Builtin.IntLiteral) | getCanonicalType: | (Builtin.IntLiteral, Builtin.IntLiteral) | getNumberOfTypes: | 2 |
|
||||
| (Int, Int, Int, Int, Int) | getName: | (Int, Int, Int, Int, Int) | getCanonicalType: | (Int, Int, Int, Int, Int) | getNumberOfTypes: | 5 |
|
||||
| (Int, String, Double) | getName: | (Int, String, Double) | getCanonicalType: | (Int, String, Double) | getNumberOfTypes: | 3 |
|
||||
| (Int, s: String, Double) | getName: | (Int, s: String, Double) | getCanonicalType: | (Int, s: String, Double) | getNumberOfTypes: | 3 |
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
| (Builtin.IntLiteral, Builtin.IntLiteral) | 0 | Builtin.IntLiteral |
|
||||
| (Builtin.IntLiteral, Builtin.IntLiteral) | 0 | Builtin.IntLiteral |
|
||||
| (Builtin.IntLiteral, Builtin.IntLiteral) | 0 | Builtin.IntLiteral |
|
||||
| (Builtin.IntLiteral, Builtin.IntLiteral) | 1 | Builtin.IntLiteral |
|
||||
| (Builtin.IntLiteral, Builtin.IntLiteral) | 1 | Builtin.IntLiteral |
|
||||
| (Builtin.IntLiteral, Builtin.IntLiteral) | 1 | Builtin.IntLiteral |
|
||||
| (Int, Int, Int, Int, Int) | 0 | Int |
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
//codeql-extractor-options: -parse-stdlib
|
||||
func f(x : (Builtin.IntLiteral, Builtin.IntLiteral)) {}
|
||||
Reference in New Issue
Block a user