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. Similarly, the -fembed-bitcode driver flag will create additional cc1 job that reads LLVM IR file.
The Clang tooling library only cares about the job that reads a source file. Instead of relying on the fact that the client injected -fsyntax-only to the driver invocation to get a single -cc1 invocation that reads the source file, this patch filters out such jobs from Compilation automatically and ignores the rest.
This fixes a test failure in ClangScanDeps/headerwithname.cpp and ClangScanDeps/headerwithnamefollowedbyinclude.cpp on AIX reported here: https://reviews.llvm.org/D103461#2841918 and clang-scan-deps failures with -fembed-bitcode.
Depends on D106788.
Seems like this could (unexpectedly?) let through a command with multiple -cc1s (if I'm reading the code right). Consider these two cases:
The first compiles two separate files; the second compiles a file with two separate architectures. But IIUC, the logic below doesn't expect this and will now let them through (ultimately, there's no reason scan-deps couldn't be updated to handle this! but that's not in scope for this patch, and maybe doesn't apply generally to clang-tooling).
Also, I'm not sure it's good that it was rejected, but I think the previous code would reject the following command-line and the new code will accept it:
I wonder if it'd be simpler to search for a supported action, and reject if zero or multiple are found. Something like: