Skip to content

Commit 018de7e

Browse files
mstorsjotmsri
authored andcommitted
[clang-scan-deps] Don't inspect Args[0] as an option (llvm#109050)
Since a26ec54, we expand the executable name to an absolute path, if it isn't already one, if found in path. This broke a couple tests in some environments; when the clang workdir resides in a path under e.g. /opt. Tests that only use a tool name like "clang-cl" would get expanded to the absolute path in the build tree. The loop for finding the last "-o" like option for clang-cl command lines would inspect all arguments, including Args[0] which is the executable name itself. As an /opt path matches Arg.starts_with("/o"), this would get detected as an object file output name in cases where there was no other explicit output argument. Thus, this fixes those tests in workdirs under e.g. /opt.
1 parent 6c9fab0 commit 018de7e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

clang/tools/clang-scan-deps/ClangScanDeps.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,12 @@ int clang_scan_deps_main(int argc, char **argv, const llvm::ToolContext &) {
837837

838838
// Reverse scan, starting at the end or at the element before "--".
839839
auto R = std::make_reverse_iterator(FlagsEnd);
840-
for (auto I = R, E = Args.rend(); I != E; ++I) {
840+
auto E = Args.rend();
841+
// Don't include Args[0] in the iteration; that's the executable, not
842+
// an option.
843+
if (E != R)
844+
E--;
845+
for (auto I = R; I != E; ++I) {
841846
StringRef Arg = *I;
842847
if (ClangCLMode) {
843848
// Ignore arguments that are preceded by "-Xclang".

0 commit comments

Comments
 (0)