Skip to content

Commit 4aefbcf

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-rebranch
2 parents 5b5e1b4 + 2d86f23 commit 4aefbcf

File tree

8 files changed

+96
-24
lines changed

8 files changed

+96
-24
lines changed

include/swift/ClangImporter/ClangImporter.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ class ClangImporter final : public ClangModuleLoader {
108108
DependencyTracker *tracker,
109109
DWARFImporterDelegate *dwarfImporterDelegate);
110110

111-
ModuleDecl *loadModuleClang(SourceLoc importLoc,
112-
ArrayRef<std::pair<Identifier, SourceLoc>> path);
113111
public:
114112
/// Create a new Clang importer that can import a suitable Clang
115113
/// module into the given ASTContext.
@@ -141,6 +139,9 @@ class ClangImporter final : public ClangModuleLoader {
141139

142140
~ClangImporter();
143141

142+
/// Only to be used by lldb-moduleimport-test.
143+
void setDWARFImporterDelegate(DWARFImporterDelegate &delegate);
144+
144145
/// Create a new clang::DependencyCollector customized to
145146
/// ClangImporter's specific uses.
146147
static std::shared_ptr<clang::DependencyCollector>

lib/ClangImporter/ClangImporter.cpp

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,11 +1573,10 @@ bool ClangImporter::canImportModule(std::pair<Identifier, SourceLoc> moduleID) {
15731573
return clangModule->isAvailable(ctx.getLangOpts(), getTargetInfo(), r, mh, m);
15741574
}
15751575

1576-
ModuleDecl *ClangImporter::loadModuleClang(
1577-
SourceLoc importLoc,
1578-
ArrayRef<std::pair<Identifier, SourceLoc>> path) {
1579-
auto &clangContext = Impl.getClangASTContext();
1580-
auto &clangHeaderSearch = Impl.getClangPreprocessor().getHeaderSearchInfo();
1576+
ModuleDecl *ClangImporter::Implementation::loadModuleClang(
1577+
SourceLoc importLoc, ArrayRef<std::pair<Identifier, SourceLoc>> path) {
1578+
auto &clangContext = getClangASTContext();
1579+
auto &clangHeaderSearch = getClangPreprocessor().getHeaderSearchInfo();
15811580

15821581
// Look up the top-level module first, to see if it exists at all.
15831582
clang::Module *clangModule = clangHeaderSearch.lookupModule(
@@ -1588,47 +1587,47 @@ ModuleDecl *ClangImporter::loadModuleClang(
15881587

15891588
// Convert the Swift import path over to a Clang import path.
15901589
SmallVector<std::pair<clang::IdentifierInfo *, clang::SourceLocation>, 4>
1591-
clangPath;
1590+
clangPath;
15921591
for (auto component : path) {
1593-
clangPath.push_back({ &clangContext.Idents.get(component.first.str()),
1594-
Impl.exportSourceLoc(component.second) } );
1592+
clangPath.push_back({&clangContext.Idents.get(component.first.str()),
1593+
exportSourceLoc(component.second)});
15951594
}
15961595

1597-
auto &rawDiagClient = Impl.Instance->getDiagnosticClient();
1596+
auto &rawDiagClient = Instance->getDiagnosticClient();
15981597
auto &diagClient = static_cast<ClangDiagnosticConsumer &>(rawDiagClient);
15991598

16001599
auto loadModule = [&](clang::ModuleIdPath path,
16011600
bool makeVisible) -> clang::ModuleLoadResult {
16021601
clang::Module::NameVisibilityKind visibility =
1603-
makeVisible ? clang::Module::AllVisible : clang::Module::Hidden;
1602+
makeVisible ? clang::Module::AllVisible : clang::Module::Hidden;
16041603

1605-
auto importRAII = diagClient.handleImport(clangPath.front().first,
1606-
importLoc);
1604+
auto importRAII =
1605+
diagClient.handleImport(clangPath.front().first, importLoc);
16071606

16081607
std::string preservedIndexStorePathOption;
1609-
auto &clangFEOpts = Impl.Instance->getFrontendOpts();
1608+
auto &clangFEOpts = Instance->getFrontendOpts();
16101609
if (!clangFEOpts.IndexStorePath.empty()) {
16111610
StringRef moduleName = path[0].first->getName();
16121611
// Ignore the SwiftShims module for the index data.
1613-
if (moduleName == Impl.SwiftContext.SwiftShimsModuleName.str()) {
1612+
if (moduleName == SwiftContext.SwiftShimsModuleName.str()) {
16141613
preservedIndexStorePathOption = clangFEOpts.IndexStorePath;
16151614
clangFEOpts.IndexStorePath.clear();
16161615
}
16171616
}
16181617

1619-
clang::SourceLocation clangImportLoc = Impl.getNextIncludeLoc();
1618+
clang::SourceLocation clangImportLoc = getNextIncludeLoc();
16201619

16211620
clang::ModuleLoadResult result =
1622-
Impl.Instance->loadModule(clangImportLoc, path, visibility,
1623-
/*IsInclusionDirective=*/false);
1621+
Instance->loadModule(clangImportLoc, path, visibility,
1622+
/*IsInclusionDirective=*/false);
16241623

16251624
if (!preservedIndexStorePathOption.empty()) {
16261625
// Restore the -index-store-path option.
16271626
clangFEOpts.IndexStorePath = preservedIndexStorePathOption;
16281627
}
16291628

16301629
if (result && makeVisible)
1631-
Impl.getClangPreprocessor().makeModuleVisible(result, clangImportLoc);
1630+
getClangPreprocessor().makeModuleVisible(result, clangImportLoc);
16321631
return result;
16331632
};
16341633

@@ -1663,13 +1662,13 @@ ModuleDecl *ClangImporter::loadModuleClang(
16631662
if (!clangModule)
16641663
return nullptr;
16651664

1666-
return Impl.finishLoadingClangModule(clangModule, /*preferOverlay=*/false);
1665+
return finishLoadingClangModule(clangModule, /*preferOverlay=*/false);
16671666
}
16681667

16691668
ModuleDecl *ClangImporter::loadModule(
16701669
SourceLoc importLoc,
16711670
ArrayRef<std::pair<Identifier, SourceLoc>> path) {
1672-
ModuleDecl *MD = loadModuleClang(importLoc, path);
1671+
ModuleDecl *MD = Impl.loadModuleClang(importLoc, path);
16731672
if (!MD)
16741673
MD = Impl.loadModuleDWARF(importLoc, path);
16751674
return MD;

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: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,14 +606,23 @@ 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:
613-
/// "Import" a module from debug info. Because debug info types are read on
617+
/// Load a module using the clang::CompilerInstance.
618+
ModuleDecl *loadModuleClang(SourceLoc importLoc,
619+
ArrayRef<std::pair<Identifier, SourceLoc>> path);
620+
621+
/// "Load" a module from debug info. Because debug info types are read on
614622
/// demand, this doesn't really do any work.
615623
ModuleDecl *loadModuleDWARF(SourceLoc importLoc,
616624
ArrayRef<std::pair<Identifier, SourceLoc>> path);
625+
617626

618627
void recordImplicitUnwrapForDecl(ValueDecl *decl, bool isIUO) {
619628
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
@@ -225,6 +225,10 @@ int main(int argc, char **argv) {
225225
desc("The directory that holds the compiler resource files"),
226226
cat(Visible));
227227

228+
opt<bool> DummyDWARFImporter(
229+
"dummy-dwarfimporter",
230+
desc("Install a dummy DWARFImporterDelegate"), cat(Visible));
231+
228232
ParseCommandLineOptions(argc, argv);
229233

230234
// Unregister our options so they don't interfere with the command line
@@ -301,6 +305,13 @@ int main(int argc, char **argv) {
301305
return 1;
302306
}
303307

308+
swift::DWARFImporterDelegate dummyDWARFImporter;
309+
if (DummyDWARFImporter) {
310+
auto *ClangImporter = static_cast<swift::ClangImporter *>(
311+
CI.getASTContext().getClangModuleLoader());
312+
ClangImporter->setDWARFImporterDelegate(dummyDWARFImporter);
313+
}
314+
304315
for (auto &Module : Modules)
305316
if (!parseASTSection(*CI.getMemoryBufferSerializedModuleLoader(),
306317
StringRef(Module.first, Module.second), modules)) {

0 commit comments

Comments
 (0)