Skip to content
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: 1 addition & 2 deletions include/swift/ClangImporter/ClangImporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ class ClangImporter final : public ClangModuleLoader {
std::vector<std::string>
getClangDepScanningInvocationArguments(ASTContext &ctx);

static std::pair<std::unique_ptr<clang::CompilerInvocation>,
std::unique_ptr<clang::DiagnosticOptions>>
static std::unique_ptr<clang::CompilerInvocation>
createClangInvocation(ClangImporter *importer,
const ClangImporterOptions &importerOpts,
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
Expand Down
21 changes: 9 additions & 12 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1284,9 +1284,7 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments(
return CI->getCC1CommandLine();
}

std::pair<std::unique_ptr<clang::CompilerInvocation>,
std::unique_ptr<clang::DiagnosticOptions>>
ClangImporter::createClangInvocation(
std::unique_ptr<clang::CompilerInvocation> ClangImporter::createClangInvocation(
ClangImporter *importer, const ClangImporterOptions &importerOpts,
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
const std::vector<std::string> &CC1Args) {
Expand All @@ -1300,19 +1298,19 @@ ClangImporter::createClangInvocation(
// option here is either generated by dependency scanner or just round tripped
// from `getClangCC1Arguments` so we don't expect it to fail. Use a simple
// printing diagnostics consumer for debugging any unexpected error.
auto diagOpts = std::make_unique<clang::DiagnosticOptions>();
clang::DiagnosticOptions diagOpts;
clang::DiagnosticsEngine clangDiags(
new clang::DiagnosticIDs(), *diagOpts,
new clang::TextDiagnosticPrinter(llvm::errs(), *diagOpts));
new clang::DiagnosticIDs(), diagOpts,
new clang::TextDiagnosticPrinter(llvm::errs(), diagOpts));

// Finally, use the CC1 command-line and the diagnostic engine
// to instantiate our Invocation.
auto CI = std::make_unique<clang::CompilerInvocation>();
if (!clang::CompilerInvocation::CreateFromArgs(
*CI, invocationArgs, clangDiags, importerOpts.clangPath.c_str()))
return {nullptr, nullptr};
return nullptr;

return {std::move(CI), std::move(diagOpts)};
return CI;
}

std::unique_ptr<ClangImporter> ClangImporter::create(
Expand Down Expand Up @@ -1360,9 +1358,8 @@ std::unique_ptr<ClangImporter> ClangImporter::create(
[] { llvm::errs() << "' '"; });
llvm::errs() << "'\n";
}
std::tie(importer->Impl.Invocation, importer->Impl.DiagnosticOptions) =
createClangInvocation(importer.get(), importerOpts, VFS,
importer->Impl.ClangArgs);
importer->Impl.Invocation = createClangInvocation(
importer.get(), importerOpts, VFS, importer->Impl.ClangArgs);
if (!importer->Impl.Invocation)
return nullptr;
}
Expand Down Expand Up @@ -1438,7 +1435,7 @@ std::unique_ptr<ClangImporter> ClangImporter::create(
ctx, instance.getVirtualFileSystemPtr(), true);
if (!swiftTargetClangArgs)
return nullptr;
auto [swiftTargetClangInvocation, clangDiagOpts] = createClangInvocation(
auto swiftTargetClangInvocation = createClangInvocation(
importer.get(), importerOpts, instance.getVirtualFileSystemPtr(),
*swiftTargetClangArgs);
if (!swiftTargetClangInvocation)
Expand Down
3 changes: 0 additions & 3 deletions lib/ClangImporter/ImporterImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,6 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
/// Clang arguments used to create the Clang invocation.
std::vector<std::string> ClangArgs;

/// Clang diagnostic options used to create the Clang invocation.
std::unique_ptr<clang::DiagnosticOptions> DiagnosticOptions;

/// Mapping from Clang swift_attr attribute text to the Swift source file(s)
/// that contain that attribute text.
///
Expand Down