diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp --- a/clang/lib/Tooling/Tooling.cpp +++ b/clang/lib/Tooling/Tooling.cpp @@ -93,8 +93,9 @@ const driver::JobList &Jobs = Compilation->getJobs(); const driver::ActionList &Actions = Compilation->getActions(); bool OffloadCompilation = false; + bool ExternalAssembler = false; if (Jobs.size() > 1) { - for (auto A : Actions){ + for (const auto *A : Actions) { // On MacOSX real actions may end up being wrapped in BindArchAction if (isa(A)) A = *A->input_begin(); @@ -115,10 +116,15 @@ OffloadCompilation = true; break; } + if (isa(A)) { + ExternalAssembler = true; + break; + } } } + bool MultipleJobsAllowed = OffloadCompilation || ExternalAssembler; if (Jobs.size() == 0 || !isa(*Jobs.begin()) || - (Jobs.size() > 1 && !OffloadCompilation)) { + (Jobs.size() > 1 && !MultipleJobsAllowed)) { SmallString<256> error_msg; llvm::raw_svector_ostream error_stream(error_msg); Jobs.Print(error_stream, "; ", true); diff --git a/clang/unittests/Tooling/ToolingTest.cpp b/clang/unittests/Tooling/ToolingTest.cpp --- a/clang/unittests/Tooling/ToolingTest.cpp +++ b/clang/unittests/Tooling/ToolingTest.cpp @@ -258,6 +258,31 @@ EXPECT_TRUE(Consumer.SawSourceManager); } +TEST(ToolInvocation, AllowExternalAssembler) { + auto OverlayFS = llvm::makeIntrusiveRefCnt( + llvm::vfs::getRealFileSystem()); + auto InMemoryFS = llvm::makeIntrusiveRefCnt(); + OverlayFS->pushOverlay(InMemoryFS); + auto Files = + llvm::makeIntrusiveRefCnt(FileSystemOptions(), OverlayFS); + + std::vector Args; + Args.push_back("tool-executable"); + Args.push_back("-fno-integrated-as"); + Args.push_back("-c"); + Args.push_back("test.cpp"); + + // We're not matching the "-c" argument with `clang::EmitObjAction` in order + // to avoid linking the clangCodeGen library. This does not affect the + // command-line handling code under test. + clang::tooling::ToolInvocation Invocation( + Args, std::make_unique(), Files.get()); + InMemoryFS->addFile("test.cpp", 0, + llvm::MemoryBuffer::getMemBuffer("int main() {}\n")); + + EXPECT_TRUE(Invocation.run()); +} + struct VerifyEndCallback : public SourceFileCallbacks { VerifyEndCallback() : BeginCalled(0), EndCalled(0), Matched(false) {} bool handleBeginSource(CompilerInstance &CI) override {