Skip to content

Commit 2ae8420

Browse files
Merge pull request swiftlang#26689 from adrian-prantl/dummy-dwarfimporter
Add back the dummy DWARFImporter test to lldb-moduleimport-test.
2 parents 5add168 + 1020d81 commit 2ae8420

File tree

7 files changed

+72
-1
lines changed

7 files changed

+72
-1
lines changed

include/swift/ClangImporter/ClangImporter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ class ClangImporter final : public ClangModuleLoader {
141141

142142
~ClangImporter();
143143

144+
/// Only to be used by lldb-moduleimport-test.
145+
void setDWARFImporterDelegate(DWARFImporterDelegate &delegate);
146+
144147
/// Create a new clang::DependencyCollector customized to
145148
/// ClangImporter's specific uses.
146149
static std::shared_ptr<clang::DependencyCollector>

lib/ClangImporter/DWARFImporter.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,12 @@ void ClangImporter::Implementation::lookupTypeDeclDWARF(
176176
receiver(importedType);
177177
}
178178
}
179+
180+
void ClangImporter::setDWARFImporterDelegate(DWARFImporterDelegate &delegate) {
181+
Impl.setDWARFImporterDelegate(delegate);
182+
}
183+
184+
void ClangImporter::Implementation::setDWARFImporterDelegate(
185+
DWARFImporterDelegate &delegate) {
186+
DWARFImporter = &delegate;
187+
}

lib/ClangImporter/ImporterImpl.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,14 +606,19 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
606606
private:
607607
/// The DWARF importer delegate, if installed.
608608
DWARFImporterDelegate *DWARFImporter = nullptr;
609+
public:
610+
/// Only used for testing.
611+
void setDWARFImporterDelegate(DWARFImporterDelegate &delegate);
612+
613+
private:
609614
/// The list of Clang modules found in the debug info.
610615
llvm::DenseMap<Identifier, LoadedFile *> DWARFModuleUnits;
611-
612616
public:
613617
/// "Import" a module from debug info. Because debug info types are read on
614618
/// demand, this doesn't really do any work.
615619
ModuleDecl *loadModuleDWARF(SourceLoc importLoc,
616620
ArrayRef<std::pair<Identifier, SourceLoc>> path);
621+
617622

618623
void recordImplicitUnwrapForDecl(ValueDecl *decl, bool isIUO) {
619624
if (!isIUO)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module ObjCModule {
2+
header "objc-header.h"
3+
export *
4+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
struct Point {
2+
int x, y;
3+
};
4+
5+
@interface ObjCClass
6+
- (instancetype)init;
7+
@end

test/DWARFImporter/basic.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// REQUIRES: executable_test
2+
// REQUIRES: objc_interop
3+
4+
// RUN: %empty-directory(%t)
5+
6+
// RUN: cp %S/Inputs/objc-header.h %S/Inputs/module.modulemap %t
7+
// RUN: %target-build-swift -emit-executable %s -g -o %t/a.out \
8+
// RUN: -module-name basic -emit-module -I%t
9+
// -DOBJC -module-name basic
10+
// RUN: %lldb-moduleimport-test -verbose -dump-module %t/a.out | %FileCheck %s
11+
12+
// RUN: rm %t/objc-header.h
13+
// RUN: %lldb-moduleimport-test -verbose -dump-module %t/a.out \
14+
// RUN: | %FileCheck %s --check-prefix=FAIL
15+
16+
// RUN: %lldb-moduleimport-test -verbose -dump-module %t/a.out \
17+
// RUN: -dummy-dwarfimporter | %FileCheck %s --check-prefix=SWIFTONLY
18+
19+
// CHECK: Importing basic... ok!
20+
// FAIL: Importing basic... ok!
21+
// SWIFTONLY: Importing basic... ok!
22+
import ObjCModule
23+
24+
let pureSwift = Int32(42)
25+
// FAIL-NOT: var_decl
26+
// CHECK: var_decl "pureSwift" {{.*}} type='Int32'
27+
// SWIFTONLY: var_decl "pureSwift" {{.*}} type='Int32'
28+
29+
let point = Point(x: 1, y: 2)
30+
// CHECK: var_decl "point" {{.*}} type='Point'
31+
// SWIFTONLY-NOT: var_decl "point"
32+

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ int main(int argc, char **argv) {
220220
desc("The directory that holds the compiler resource files"),
221221
cat(Visible));
222222

223+
opt<bool> DummyDWARFImporter(
224+
"dummy-dwarfimporter",
225+
desc("Install a dummy DWARFImporterDelegate"), cat(Visible));
226+
223227
ParseCommandLineOptions(argc, argv);
224228

225229
// Unregister our options so they don't interfere with the command line
@@ -296,6 +300,13 @@ int main(int argc, char **argv) {
296300
return 1;
297301
}
298302

303+
swift::DWARFImporterDelegate dummyDWARFImporter;
304+
if (DummyDWARFImporter) {
305+
auto *ClangImporter = static_cast<swift::ClangImporter *>(
306+
CI.getASTContext().getClangModuleLoader());
307+
ClangImporter->setDWARFImporterDelegate(dummyDWARFImporter);
308+
}
309+
299310
for (auto &Module : Modules)
300311
if (!parseASTSection(*CI.getMemoryBufferSerializedModuleLoader(),
301312
StringRef(Module.first, Module.second), modules)) {

0 commit comments

Comments
 (0)