From c075aa31af47f2b5a38cd160735e047f990412f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20Sch=C3=BCtt?= Date: Mon, 22 Feb 2021 12:27:41 +0100 Subject: [PATCH] SR-14256: fixes swift-frontend crash --- include/swift/AST/DiagnosticsFrontend.def | 3 +++ lib/FrontendTool/FrontendTool.cpp | 24 +++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/include/swift/AST/DiagnosticsFrontend.def b/include/swift/AST/DiagnosticsFrontend.def index 31455bdf50eb5..b56deb87a56d5 100644 --- a/include/swift/AST/DiagnosticsFrontend.def +++ b/include/swift/AST/DiagnosticsFrontend.def @@ -46,6 +46,9 @@ WARNING(warning_inferred_simulator_target,none, ERROR(error_argument_not_allowed_with, none, "argument '%0' is not allowed with '%1'", (StringRef, StringRef)) +ERROR(error_not_a_swift_file, none, + "not a swift file: '%0'", (StringRef)) + WARNING(warning_argument_not_supported_with_optimization, none, "argument '%0' is not supported with optimization", (StringRef)) diff --git a/lib/FrontendTool/FrontendTool.cpp b/lib/FrontendTool/FrontendTool.cpp index 119e762d1215e..2438082a2c3cb 100644 --- a/lib/FrontendTool/FrontendTool.cpp +++ b/lib/FrontendTool/FrontendTool.cpp @@ -1270,19 +1270,19 @@ static bool performCompile(CompilerInstance &Instance, return true; } - assert([&]() -> bool { - if (FrontendOptions::shouldActionOnlyParse(Action)) { - // Parsing gets triggered lazily, but let's make sure we have the right - // input kind. - return llvm::all_of( - opts.InputsAndOutputs.getAllInputs(), [](const InputFile &IF) { - const auto kind = IF.getType(); - return kind == file_types::TY_Swift || - kind == file_types::TY_SwiftModuleInterfaceFile; - }); + if (FrontendOptions::shouldActionOnlyParse(Action)) { + // Parsing gets triggered lazily, but let's make sure we have the right + // input kind. + for (const InputFile &IF : opts.InputsAndOutputs.getAllInputs()) { + const auto kind = IF.getType(); + if (kind != file_types::TY_Swift && + kind != file_types::TY_SwiftModuleInterfaceFile) { + Instance.getDiags().diagnose(SourceLoc(), diag::error_not_a_swift_file, + IF.getFileName()); + return true; + } } - return true; - }() && "Only supports parsing .swift files"); + } bool hadError = performAction(Instance, ReturnValue, observer);