[clang] [clang-scan-deps] Don't inspect Args[0] as an option (PR #109050)
Martin Storsjö via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 17 14:08:17 PDT 2024
https://github.com/mstorsjo created https://github.com/llvm/llvm-project/pull/109050
Since a26ec542371652e1d774696e90016fd5b0b1c191, 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.
>From 52f9955bd6a14e12ee5a54e5b650158812866cce Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin at martin.st>
Date: Wed, 18 Sep 2024 00:03:00 +0300
Subject: [PATCH] [clang-scan-deps] Don't inspect Args[0] as an option
Since a26ec542371652e1d774696e90016fd5b0b1c191, 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.
---
clang/tools/clang-scan-deps/ClangScanDeps.cpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index ac68e3605a10cb..5d975f8aa82ee5 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -839,9 +839,11 @@ int clang_scan_deps_main(int argc, char **argv, const llvm::ToolContext &) {
auto R = std::make_reverse_iterator(FlagsEnd);
for (auto I = R, E = Args.rend(); I != E; ++I) {
StringRef Arg = *I;
+ if ((I + 1) == E) // Don't inspect Args[0] as an option.
+ break;
if (ClangCLMode) {
// Ignore arguments that are preceded by "-Xclang".
- if ((I + 1) != E && I[1] == "-Xclang")
+ if (I[1] == "-Xclang")
continue;
if (LastO.empty()) {
// With clang-cl, the output obj file can be specified with
More information about the cfe-commits
mailing list