Skip to content

Commit a14f345

Browse files
committed
lldb-moduleimport-test: Add support for testing Demangle::getTypeForMangling()
The -type-from-mangled flag now uses the new API. The -type-from-mangled-old flag uses the old API, ide::getTypeFromMangledSymbolname(). For now, just change all existing tests to use the -type-from-mangled-old flag; I'll be adding new tests for the new API shortly.
1 parent ed20908 commit a14f345

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

test/DebugInfo/DumpDeclFromMangledName.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// INVALID-DECL: patatino does not exist, exiting.
2020

2121
// RUN: not %lldb-moduleimport-test %t/DeclReconstr \
22-
// RUN: --type-from-mangled=patatino 2>&1 | \
22+
// RUN: --type-from-mangled-old=patatino 2>&1 | \
2323
// RUN: %FileCheck %s --check-prefix=INVALID-TYPE
2424
// INVALID-TYPE: patatino does not exist, exiting.
2525

test/DebugInfo/DumpTypeFromMangledName.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
// RUN: %target-build-swift -emit-executable %s -g -o %t/TypeReconstr -emit-module
1010
// RUN: %lldb-moduleimport-test %t/TypeReconstr \
11-
// RUN: -type-from-mangled=%t.input > %t.output 2>&1
11+
// RUN: -type-from-mangled-old=%t.input > %t.output 2>&1
1212
// RUN: diff %t.check %t.output
1313

1414
// REQUIRES: executable_test

tools/lldb-moduleimport-test/lldb-moduleimport-test.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
//
1717
//===----------------------------------------------------------------------===//
1818

19+
#include "swift/AST/ASTDemangler.h"
1920
#include "swift/ASTSectionImporter/ASTSectionImporter.h"
2021
#include "swift/Frontend/Frontend.h"
2122
#include "swift/IDE/Utils.h"
@@ -92,6 +93,20 @@ static void resolveDeclFromMangledNameList(
9293

9394
static void resolveTypeFromMangledNameList(
9495
swift::ASTContext &Ctx, llvm::ArrayRef<std::string> MangledNames) {
96+
for (auto &Mangled : MangledNames) {
97+
swift::Type ResolvedType =
98+
swift::Demangle::getTypeForMangling(Ctx, Mangled);
99+
if (!ResolvedType) {
100+
llvm::outs() << "Can't resolve type of " << Mangled << "\n";
101+
} else {
102+
ResolvedType->print(llvm::outs());
103+
llvm::outs() << "\n";
104+
}
105+
}
106+
}
107+
108+
static void resolveTypeFromMangledNameListOld(
109+
swift::ASTContext &Ctx, llvm::ArrayRef<std::string> MangledNames) {
95110
std::string Error;
96111
for (auto &Mangled : MangledNames) {
97112
swift::Type ResolvedType =
@@ -207,6 +222,11 @@ int main(int argc, char **argv) {
207222
"type-from-mangled", desc("dump type from mangled names list"),
208223
cat(Visible));
209224

225+
opt<std::string> DumpTypeFromMangledOld(
226+
"type-from-mangled-old", desc("dump type from mangled names list using old "
227+
"TypeReconstruction API"),
228+
cat(Visible));
229+
210230
opt<std::string> ResourceDir(
211231
"resource-dir",
212232
desc("The directory that holds the compiler resource files"),
@@ -223,6 +243,7 @@ int main(int argc, char **argv) {
223243
ModuleCachePath.removeArgument();
224244
DumpModule.removeArgument();
225245
DumpTypeFromMangled.removeArgument();
246+
DumpTypeFromMangledOld.removeArgument();
226247
InputNames.removeArgument();
227248

228249
auto validateInputFile = [](std::string Filename) {
@@ -241,6 +262,8 @@ int main(int argc, char **argv) {
241262

242263
if (!validateInputFile(DumpTypeFromMangled))
243264
return 1;
265+
if (!validateInputFile(DumpTypeFromMangledOld))
266+
return 1;
244267
if (!validateInputFile(DumpDeclFromMangled))
245268
return 1;
246269

@@ -330,6 +353,11 @@ int main(int argc, char **argv) {
330353
collectMangledNames(DumpTypeFromMangled, MangledNames);
331354
resolveTypeFromMangledNameList(CI.getASTContext(), MangledNames);
332355
}
356+
if (!DumpTypeFromMangledOld.empty()) {
357+
llvm::SmallVector<std::string, 8> MangledNames;
358+
collectMangledNames(DumpTypeFromMangledOld, MangledNames);
359+
resolveTypeFromMangledNameListOld(CI.getASTContext(), MangledNames);
360+
}
333361
if (!DumpDeclFromMangled.empty()) {
334362
llvm::SmallVector<std::string, 8> MangledNames;
335363
collectMangledNames(DumpDeclFromMangled, MangledNames);

validation-test/Serialization/bridging-header-first.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
// RUN: %target-build-swift -emit-module -emit-executable %s -g -I %S/Inputs/bridging-header-first/ -import-objc-header %S/Inputs/bridging-header-first/bridging.h -o %t/main
44
// RUN: llvm-bcanalyzer -dump %t/main.swiftmodule | %FileCheck -check-prefix CHECK-DUMP %s
5-
// RUN: %lldb-moduleimport-test %t/main -type-from-mangled %S/Inputs/bridging-header-first/mangled.txt 2>&1 | %FileCheck -check-prefix CHECK-RESOLVED-TYPE %s
5+
// RUN: %lldb-moduleimport-test %t/main -type-from-mangled-old %S/Inputs/bridging-header-first/mangled.txt 2>&1 | %FileCheck -check-prefix CHECK-RESOLVED-TYPE %s
66

77
// RUN: %target-build-swift -emit-module -emit-executable %s -g -I %S/Inputs/bridging-header-first/ -import-objc-header %S/Inputs/bridging-header-first/bridging.h -o %t/main -whole-module-optimization
88
// RUN: llvm-bcanalyzer -dump %t/main.swiftmodule | %FileCheck -check-prefix CHECK-DUMP %s
9-
// RUN: %lldb-moduleimport-test %t/main -type-from-mangled %S/Inputs/bridging-header-first/mangled.txt 2>&1 | %FileCheck -check-prefix CHECK-RESOLVED-TYPE %s
9+
// RUN: %lldb-moduleimport-test %t/main -type-from-mangled-old %S/Inputs/bridging-header-first/mangled.txt 2>&1 | %FileCheck -check-prefix CHECK-RESOLVED-TYPE %s
1010

1111
// REQUIRES: objc_interop
1212

0 commit comments

Comments
 (0)