Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang-scan-deps] Don't inspect Args[0] as an option #109050

Merged
merged 1 commit into from
Sep 19, 2024

Conversation

mstorsjo
Copy link
Member

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.

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Sep 17, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 17, 2024

@llvm/pr-subscribers-clang

Author: Martin Storsjö (mstorsjo)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/109050.diff

1 Files Affected:

  • (modified) clang/tools/clang-scan-deps/ClangScanDeps.cpp (+3-1)
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

@rorth
Copy link
Collaborator

rorth commented Sep 18, 2024

I can confirm that the patch fixes the error I'm seeing on the Solaris buildbots. Thanks.

@mstorsjo mstorsjo force-pushed the clang-scan-deps-argv0 branch from 52f9955 to 73dbd69 Compare September 19, 2024 11:17
Copy link

github-actions bot commented Sep 19, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

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.
@mstorsjo mstorsjo force-pushed the clang-scan-deps-argv0 branch from 73dbd69 to d7f4615 Compare September 19, 2024 11:23
@mstorsjo mstorsjo merged commit cead904 into llvm:main Sep 19, 2024
8 checks passed
@mstorsjo mstorsjo deleted the clang-scan-deps-argv0 branch September 19, 2024 17:46
tmsri pushed a commit to tmsri/llvm-project that referenced this pull request Sep 19, 2024
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.
llvmbot pushed a commit to llvmbot/llvm-project that referenced this pull request Sep 24, 2024
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.

(cherry picked from commit cead904)
tru pushed a commit to llvmbot/llvm-project that referenced this pull request Oct 1, 2024
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.

(cherry picked from commit cead904)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants