@@ -1312,7 +1312,8 @@ std::unique_ptr<clang::CompilerInvocation> ClangImporter::createClangInvocation(
13121312}
13131313
13141314std::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 ,
0 commit comments