jansvoboda11 created this revision. jansvoboda11 added reviewers: Bigcheese, dexonsmith, bmahjour. jansvoboda11 added a project: clang. jansvoboda11 requested review of this revision.
When "-fno-integrated-as" is passed to the Clang driver (or set by default by a specific toolchain), it will construct an assembler job in addition to the cc1 job. This patch handles such case in the Clang tooling library which by default expects only a single job to be present. This fixes a test failure in `ClangScanDeps/headerwithname.cpp` and `ClangScanDeps/headerwithnamefollowedbyinclude.cpp` on AIX reported here: https://reviews.llvm.org/D103461#2841918 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D105695 Files: clang/lib/Tooling/Tooling.cpp clang/unittests/Tooling/ToolingTest.cpp Index: clang/unittests/Tooling/ToolingTest.cpp =================================================================== --- clang/unittests/Tooling/ToolingTest.cpp +++ clang/unittests/Tooling/ToolingTest.cpp @@ -258,6 +258,31 @@ EXPECT_TRUE(Consumer.SawSourceManager); } +TEST(ToolInvocation, AllowExternalAssembler) { + auto OverlayFS = llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>( + llvm::vfs::getRealFileSystem()); + auto InMemoryFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); + OverlayFS->pushOverlay(InMemoryFS); + auto Files = + llvm::makeIntrusiveRefCnt<FileManager>(FileSystemOptions(), OverlayFS); + + std::vector<std::string> 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<SyntaxOnlyAction>(), 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 { Index: clang/lib/Tooling/Tooling.cpp =================================================================== --- clang/lib/Tooling/Tooling.cpp +++ 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<driver::BindArchAction>(A)) A = *A->input_begin(); @@ -115,10 +116,15 @@ OffloadCompilation = true; break; } + if (isa<driver::AssembleJobAction>(A)) { + ExternalAssembler = true; + break; + } } } + bool MultipleJobsAllowed = OffloadCompilation || ExternalAssembler; if (Jobs.size() == 0 || !isa<driver::Command>(*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);
Index: clang/unittests/Tooling/ToolingTest.cpp =================================================================== --- clang/unittests/Tooling/ToolingTest.cpp +++ clang/unittests/Tooling/ToolingTest.cpp @@ -258,6 +258,31 @@ EXPECT_TRUE(Consumer.SawSourceManager); } +TEST(ToolInvocation, AllowExternalAssembler) { + auto OverlayFS = llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>( + llvm::vfs::getRealFileSystem()); + auto InMemoryFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); + OverlayFS->pushOverlay(InMemoryFS); + auto Files = + llvm::makeIntrusiveRefCnt<FileManager>(FileSystemOptions(), OverlayFS); + + std::vector<std::string> 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<SyntaxOnlyAction>(), 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 { Index: clang/lib/Tooling/Tooling.cpp =================================================================== --- clang/lib/Tooling/Tooling.cpp +++ 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<driver::BindArchAction>(A)) A = *A->input_begin(); @@ -115,10 +116,15 @@ OffloadCompilation = true; break; } + if (isa<driver::AssembleJobAction>(A)) { + ExternalAssembler = true; + break; + } } } + bool MultipleJobsAllowed = OffloadCompilation || ExternalAssembler; if (Jobs.size() == 0 || !isa<driver::Command>(*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);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits