@@ -1427,22 +1427,12 @@ ClangImporter::create(ASTContext &ctx,
1427
1427
importer.get (), importerOpts, VFS, *swiftTargetClangArgs);
1428
1428
if (!swiftTargetClangInvocation)
1429
1429
return nullptr ;
1430
- auto targetInfo = clang::TargetInfo::CreateTargetInfo (
1431
- clangDiags, swiftTargetClangInvocation->getTargetOpts ());
1432
- // Ensure the target info has configured target-specific defines
1433
- std::string defineBuffer;
1434
- llvm::raw_string_ostream predefines (defineBuffer);
1435
- clang::MacroBuilder builder (predefines);
1436
- targetInfo->getTargetDefines (instance.getLangOpts (), builder);
1437
- importer->Impl .setSwiftTargetInfo (targetInfo);
1438
- importer->Impl .setSwiftCodeGenOptions (new clang::CodeGenOptions (
1439
- swiftTargetClangInvocation->getCodeGenOpts ()));
1430
+
1431
+ importer->Impl .configureOptionsForCodeGen (clangDiags,
1432
+ swiftTargetClangInvocation.get ());
1440
1433
} else {
1441
- // Just use the existing Invocation's directly
1442
- importer->Impl .setSwiftTargetInfo (clang::TargetInfo::CreateTargetInfo (
1443
- clangDiags, importer->Impl .Invocation ->getTargetOpts ()));
1444
- importer->Impl .setSwiftCodeGenOptions (
1445
- new clang::CodeGenOptions (importer->Impl .Invocation ->getCodeGenOpts ()));
1434
+ // Set using the existing invocation.
1435
+ importer->Impl .configureOptionsForCodeGen (clangDiags);
1446
1436
}
1447
1437
1448
1438
// Create the associated action.
@@ -4132,7 +4122,7 @@ clang::TargetInfo &ClangImporter::getModuleAvailabilityTarget() const {
4132
4122
}
4133
4123
4134
4124
clang::TargetInfo &ClangImporter::getTargetInfo () const {
4135
- return * Impl.getSwiftTargetInfo ();
4125
+ return Impl.getCodeGenTargetInfo ();
4136
4126
}
4137
4127
4138
4128
clang::ASTContext &ClangImporter::getClangASTContext () const {
@@ -4165,7 +4155,7 @@ clang::Sema &ClangImporter::getClangSema() const {
4165
4155
}
4166
4156
4167
4157
clang::CodeGenOptions &ClangImporter::getCodeGenOpts () const {
4168
- return * Impl.getSwiftCodeGenOptions ();
4158
+ return Impl.getCodeGenOptions ();
4169
4159
}
4170
4160
4171
4161
std::string ClangImporter::getClangModuleHash () const {
@@ -4612,6 +4602,37 @@ void ClangImporter::Implementation::getMangledName(
4612
4602
}
4613
4603
}
4614
4604
4605
+ void ClangImporter::Implementation::configureOptionsForCodeGen (
4606
+ clang::DiagnosticsEngine &Diags, clang::CompilerInvocation *CI) {
4607
+ clang::TargetInfo *targetInfo = nullptr ;
4608
+ if (CI) {
4609
+ TargetOpts.reset (new clang::TargetOptions (std::move (CI->getTargetOpts ())));
4610
+ CodeGenOpts.reset (
4611
+ new clang::CodeGenOptions (std::move (CI->getCodeGenOpts ())));
4612
+ targetInfo = clang::TargetInfo::CreateTargetInfo (Diags, *TargetOpts);
4613
+
4614
+ // Ensure the target info has configured target-specific defines
4615
+ std::string defineBuffer;
4616
+ llvm::raw_string_ostream predefines (defineBuffer);
4617
+ clang::MacroBuilder builder (predefines);
4618
+ targetInfo->getTargetDefines (Instance->getLangOpts (), builder);
4619
+ } else {
4620
+ targetInfo =
4621
+ clang::TargetInfo::CreateTargetInfo (Diags, Invocation->getTargetOpts ());
4622
+ }
4623
+
4624
+ CodeGenTargetInfo.reset (targetInfo);
4625
+ }
4626
+
4627
+ clang::CodeGenOptions &
4628
+ ClangImporter::Implementation::getCodeGenOptions () const {
4629
+ if (CodeGenOpts) {
4630
+ return *CodeGenOpts.get ();
4631
+ }
4632
+
4633
+ return Invocation->getCodeGenOpts ();
4634
+ }
4635
+
4615
4636
// ---------------------------------------------------------------------------
4616
4637
// Swift lookup tables
4617
4638
// ---------------------------------------------------------------------------
0 commit comments