Skip to content

Add back the dummy DWARFImporter test to lldb-moduleimport-test. #26689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/swift/ClangImporter/ClangImporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ class ClangImporter final : public ClangModuleLoader {

~ClangImporter();

/// Only to be used by lldb-moduleimport-test.
void setDWARFImporterDelegate(DWARFImporterDelegate &delegate);

/// Create a new clang::DependencyCollector customized to
/// ClangImporter's specific uses.
static std::shared_ptr<clang::DependencyCollector>
Expand Down
9 changes: 9 additions & 0 deletions lib/ClangImporter/DWARFImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,12 @@ void ClangImporter::Implementation::lookupTypeDeclDWARF(
receiver(importedType);
}
}

void ClangImporter::setDWARFImporterDelegate(DWARFImporterDelegate &delegate) {
Impl.setDWARFImporterDelegate(delegate);
}

void ClangImporter::Implementation::setDWARFImporterDelegate(
DWARFImporterDelegate &delegate) {
DWARFImporter = &delegate;
}
7 changes: 6 additions & 1 deletion lib/ClangImporter/ImporterImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -606,14 +606,19 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
private:
/// The DWARF importer delegate, if installed.
DWARFImporterDelegate *DWARFImporter = nullptr;
public:
/// Only used for testing.
void setDWARFImporterDelegate(DWARFImporterDelegate &delegate);

private:
/// The list of Clang modules found in the debug info.
llvm::DenseMap<Identifier, LoadedFile *> DWARFModuleUnits;

public:
/// "Import" a module from debug info. Because debug info types are read on
/// demand, this doesn't really do any work.
ModuleDecl *loadModuleDWARF(SourceLoc importLoc,
ArrayRef<std::pair<Identifier, SourceLoc>> path);


void recordImplicitUnwrapForDecl(Decl *decl, bool isIUO) {
#if !defined(NDEBUG)
Expand Down
4 changes: 4 additions & 0 deletions test/DWARFImporter/Inputs/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module ObjCModule {
header "objc-header.h"
export *
}
7 changes: 7 additions & 0 deletions test/DWARFImporter/Inputs/objc-header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
struct Point {
int x, y;
};

@interface ObjCClass
- (instancetype)init;
@end
32 changes: 32 additions & 0 deletions test/DWARFImporter/basic.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// REQUIRES: executable_test
// REQUIRES: objc_interop

// RUN: %empty-directory(%t)

// RUN: cp %S/Inputs/objc-header.h %S/Inputs/module.modulemap %t
// RUN: %target-build-swift -emit-executable %s -g -o %t/a.out \
// RUN: -module-name basic -emit-module -I%t
// -DOBJC -module-name basic
// RUN: %lldb-moduleimport-test -verbose -dump-module %t/a.out | %FileCheck %s

// RUN: rm %t/objc-header.h
// RUN: %lldb-moduleimport-test -verbose -dump-module %t/a.out \
// RUN: | %FileCheck %s --check-prefix=FAIL

// RUN: %lldb-moduleimport-test -verbose -dump-module %t/a.out \
// RUN: -dummy-dwarfimporter | %FileCheck %s --check-prefix=SWIFTONLY

// CHECK: Importing basic... ok!
// FAIL: Importing basic... ok!
// SWIFTONLY: Importing basic... ok!
import ObjCModule

let pureSwift = Int32(42)
// FAIL-NOT: var_decl
// CHECK: var_decl "pureSwift" {{.*}} type='Int32'
// SWIFTONLY: var_decl "pureSwift" {{.*}} type='Int32'

let point = Point(x: 1, y: 2)
// CHECK: var_decl "point" {{.*}} type='Point'
// SWIFTONLY-NOT: var_decl "point"

11 changes: 11 additions & 0 deletions tools/lldb-moduleimport-test/lldb-moduleimport-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ int main(int argc, char **argv) {
desc("The directory that holds the compiler resource files"),
cat(Visible));

opt<bool> DummyDWARFImporter(
"dummy-dwarfimporter",
desc("Install a dummy DWARFImporterDelegate"), cat(Visible));

ParseCommandLineOptions(argc, argv);

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

swift::DWARFImporterDelegate dummyDWARFImporter;
if (DummyDWARFImporter) {
auto *ClangImporter = static_cast<swift::ClangImporter *>(
CI.getASTContext().getClangModuleLoader());
ClangImporter->setDWARFImporterDelegate(dummyDWARFImporter);
}

for (auto &Module : Modules)
if (!parseASTSection(*CI.getMemoryBufferSerializedModuleLoader(),
StringRef(Module.first, Module.second), modules)) {
Expand Down