[PATCH] D105695: [clang][tooling] Accept Clang invocations with "-fno-integrated-as"
Jan Svoboda via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 9 05:19:45 PDT 2021
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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105695.357484.patch
Type: text/x-patch
Size: 2684 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210709/395de596/attachment.bin>
More information about the cfe-commits
mailing list