Skip to content

Commit d213b05

Browse files
committed
Test
1 parent a69dbb3 commit d213b05

File tree

8 files changed

+62
-39
lines changed

8 files changed

+62
-39
lines changed

include/swift/ClangImporter/ClangImporter.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ class ClangImporter final : public ClangModuleLoader {
200200
/// \returns a new Clang module importer, or null (with a diagnostic) if
201201
/// an error occurred.
202202
static std::unique_ptr<ClangImporter>
203-
create(ASTContext &ctx, std::string swiftPCHHash = "",
203+
create(ASTContext &ctx,
204+
const IRGenOptions *IRGenOpts = nullptr,
205+
std::string swiftPCHHash = "",
204206
DependencyTracker *tracker = nullptr,
205207
DWARFImporterDelegate *dwarfImporterDelegate = nullptr,
206208
bool ignoreFileMapping = false);

lib/ClangImporter/ClangImporter.cpp

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1312,7 +1312,8 @@ std::unique_ptr<clang::CompilerInvocation> ClangImporter::createClangInvocation(
13121312
}
13131313

13141314
std::unique_ptr<ClangImporter> ClangImporter::create(
1315-
ASTContext &ctx, std::string swiftPCHHash, DependencyTracker *tracker,
1315+
ASTContext &ctx, const IRGenOptions *IRGenOpts, std::string swiftPCHHash,
1316+
DependencyTracker *tracker,
13161317
DWARFImporterDelegate *dwarfImporterDelegate, bool ignoreFileMapping) {
13171318
std::unique_ptr<ClangImporter> importer{
13181319
new ClangImporter(ctx, tracker, dwarfImporterDelegate)};
@@ -1446,6 +1447,48 @@ std::unique_ptr<ClangImporter> ClangImporter::create(
14461447
importer->Impl.configureOptionsForCodeGen(clangDiags);
14471448
}
14481449

1450+
if (IRGenOpts) {
1451+
// We need to set the AST-affecting CodeGenOpts here early so that
1452+
// the clang module cache hash will be consistent throughout. Also
1453+
// prefer to set the AST-benign ones here unless they are computed
1454+
// after this point or may var per inputs.
1455+
auto &CGO = importer->getCodeGenOpts();
1456+
CGO.OptimizationLevel = IRGenOpts->shouldOptimize() ? 3 : 0;
1457+
CGO.DebugTypeExtRefs = !IRGenOpts->DisableClangModuleSkeletonCUs;
1458+
switch (IRGenOpts->DebugInfoLevel) {
1459+
case IRGenDebugInfoLevel::None:
1460+
CGO.setDebugInfo(llvm::codegenoptions::DebugInfoKind::NoDebugInfo);
1461+
break;
1462+
case IRGenDebugInfoLevel::LineTables:
1463+
CGO.setDebugInfo(llvm::codegenoptions::DebugInfoKind::DebugLineTablesOnly);
1464+
break;
1465+
case IRGenDebugInfoLevel::ASTTypes:
1466+
case IRGenDebugInfoLevel::DwarfTypes:
1467+
CGO.setDebugInfo(llvm::codegenoptions::DebugInfoKind::FullDebugInfo);
1468+
break;
1469+
}
1470+
switch (IRGenOpts->DebugInfoFormat) {
1471+
case IRGenDebugInfoFormat::None:
1472+
break;
1473+
case IRGenDebugInfoFormat::DWARF:
1474+
CGO.DebugCompilationDir = IRGenOpts->DebugCompilationDir;
1475+
CGO.DwarfVersion = IRGenOpts->DWARFVersion;
1476+
break;
1477+
case IRGenDebugInfoFormat::CodeView:
1478+
CGO.EmitCodeView = true;
1479+
CGO.DebugCompilationDir = IRGenOpts->DebugCompilationDir;
1480+
break;
1481+
}
1482+
if (!IRGenOpts->TrapFuncName.empty()) {
1483+
CGO.TrapFuncName = IRGenOpts->TrapFuncName;
1484+
}
1485+
// We don't need to perform coverage mapping for any Clang decls we've
1486+
// synthesized, as they have no user-written code. This is also needed to
1487+
// avoid a Clang crash when attempting to emit coverage for decls without
1488+
// source locations (rdar://100172217).
1489+
CGO.CoverageMapping = false;
1490+
}
1491+
14491492
// Create the associated action.
14501493
importer->Impl.Action.reset(new ParsingAction(*importer,
14511494
importer->Impl,

lib/DriverTool/modulewrap_main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,9 @@ int modulewrap_main(ArrayRef<const char *> Args, const char *Argv0,
198198
registerParseRequestFunctions(ASTCtx.evaluator);
199199
registerTypeCheckerRequestFunctions(ASTCtx.evaluator);
200200

201-
ASTCtx.addModuleLoader(ClangImporter::create(ASTCtx, "",
202-
nullptr, nullptr,
201+
IRGenOptions IRGenOpts;
202+
ASTCtx.addModuleLoader(ClangImporter::create(ASTCtx, &IRGenOpts,
203+
"", nullptr, nullptr,
203204
true),
204205
true);
205206
ModuleDecl *M =

lib/Frontend/Frontend.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,8 @@ bool CompilerInstance::setUpModuleLoaders() {
872872
// Otherwise, we just keep it around as our interface to Clang's ABI
873873
// knowledge.
874874
std::unique_ptr<ClangImporter> clangImporter =
875-
ClangImporter::create(*Context, Invocation.getPCHHash(),
875+
ClangImporter::create(*Context, &Invocation.getIRGenOptions(),
876+
Invocation.getPCHHash(),
876877
getDependencyTracker());
877878
if (!clangImporter) {
878879
Diagnostics.diagnose(SourceLoc(), diag::error_clang_importer_create_fail);

lib/IRGen/IRGenModule.cpp

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -108,50 +108,20 @@ static clang::CodeGenerator *createClangCodeGenerator(ASTContext &Context,
108108

109109
auto &CGTI = Importer->getTargetInfo();
110110
auto &CGO = Importer->getCodeGenOpts();
111-
CGO.OptimizationLevel = Opts.shouldOptimize() ? 3 : 0;
112111

113-
CGO.DebugTypeExtRefs = !Opts.DisableClangModuleSkeletonCUs;
112+
// Here we set the AST-benign CodeGenOpts options only. Set the
113+
// AST-affecting ones early in ClangImporter::create.
114114
CGO.DiscardValueNames = !Opts.shouldProvideValueNames();
115-
switch (Opts.DebugInfoLevel) {
116-
case IRGenDebugInfoLevel::None:
117-
CGO.setDebugInfo(llvm::codegenoptions::DebugInfoKind::NoDebugInfo);
118-
break;
119-
case IRGenDebugInfoLevel::LineTables:
120-
CGO.setDebugInfo(llvm::codegenoptions::DebugInfoKind::DebugLineTablesOnly);
121-
break;
122-
case IRGenDebugInfoLevel::ASTTypes:
123-
case IRGenDebugInfoLevel::DwarfTypes:
124-
CGO.setDebugInfo(llvm::codegenoptions::DebugInfoKind::FullDebugInfo);
125-
break;
126-
}
127115
switch (Opts.DebugInfoFormat) {
128116
case IRGenDebugInfoFormat::None:
129117
break;
130118
case IRGenDebugInfoFormat::DWARF:
131-
CGO.DebugCompilationDir = Opts.DebugCompilationDir;
132-
CGO.DwarfVersion = Opts.DWARFVersion;
133-
CGO.DwarfDebugFlags =
134-
Opts.getDebugFlags(PD, Context.LangOpts.EnableCXXInterop,
135-
Context.LangOpts.hasFeature(Feature::Embedded));
136-
break;
137119
case IRGenDebugInfoFormat::CodeView:
138-
CGO.EmitCodeView = true;
139-
CGO.DebugCompilationDir = Opts.DebugCompilationDir;
140-
// This actually contains the debug flags for codeview.
141120
CGO.DwarfDebugFlags =
142121
Opts.getDebugFlags(PD, Context.LangOpts.EnableCXXInterop,
143122
Context.LangOpts.hasFeature(Feature::Embedded));
144123
break;
145124
}
146-
if (!Opts.TrapFuncName.empty()) {
147-
CGO.TrapFuncName = Opts.TrapFuncName;
148-
}
149-
150-
// We don't need to perform coverage mapping for any Clang decls we've
151-
// synthesized, as they have no user-written code. This is also needed to
152-
// avoid a Clang crash when attempting to emit coverage for decls without
153-
// source locations (rdar://100172217).
154-
CGO.CoverageMapping = false;
155125

156126
auto &VFS = Importer->getClangInstance().getVirtualFileSystem();
157127
auto &HSI = Importer->getClangPreprocessor()

test/DebugInfo/BridgingHeaderPCH-Type.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %target-swift-frontend \
2-
// RUN: -emit-pch %S/Inputs/BridgingHeader.h -o %t.pch
2+
// RUN: -emit-pch %S/Inputs/BridgingHeader.h -o %t.pch -g
33
// RUN: %target-swift-frontend \
44
// RUN: -import-objc-header %t.pch -emit-ir -g %s -o - | %FileCheck %s
55

test/DebugInfo/BridgingHeaderPCH.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %target-swift-frontend \
2-
// RUN: -emit-pch %S/Inputs/InlineBridgingHeader.h -o %t.pch
2+
// RUN: -emit-pch %S/Inputs/InlineBridgingHeader.h -o %t.pch -g
33
// RUN: %target-swift-frontend \
44
// RUN: -import-objc-header %t.pch -emit-ir -g %s -o - | %FileCheck %s
55

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
// RUN: %target-swift-frontend -c -emit-module-path %t/Foo.swiftmodule -g -cxx-interoperability-mode=default %t/Test.swift -module-cache-path %t/clang-module-cache
4+
5+
//--- Test.swift
6+
// Empty

0 commit comments

Comments
 (0)