Swift: mangle builtin and tuple types

This commit is contained in:
Paolo Tranquilli
2023-03-14 11:32:52 +01:00
parent 383b2e183d
commit b269bd5010
6 changed files with 34 additions and 3 deletions

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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
) {}

View File

@@ -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 |

View File

@@ -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 |

View File

@@ -0,0 +1,2 @@
//codeql-extractor-options: -parse-stdlib
func f(x : (Builtin.IntLiteral, Builtin.IntLiteral)) {}