Hello,
I suspect that there is a bug in how Clang-FindBinUtils.cmake searches for clang-related executables (e.g. clang-scan-deps). The order of the search appears incorrect.
The search iterates over two categories:
- first over all possible names (e.g. clang-scan-deps-20.1, clang-scan-deps-20, clang-scan-deps)
- and then over all possible locations (directories)
The current implementation iterates over the names first, and then over the directories. I believe the order should be swapped.
Pseudo-code:
// Current behavior (suspicious/buggy)
for (each possible name) {
for (each possible directory) {
check_if_file_exists(join_path(directory, name));
}
}
// Expected behavior
for (each possible directory) {
for (each possible name) {
check_if_file_exists(join_path(directory, name));
}
}
Concrete example:
Let’s have the following clang binaries on a Linux system:
/usr/bin:
clang++-20
clang-scan-deps-20
...
/opt/my_own_clang_build/bin:
clang++
clang-scan-deps
...
Let’s assume CMAKE_CXX_COMPILER variable is set to /opt/my_own_clang_build/bin/clang++.
In such a case, Clang-FindBinUtils.cmake will search for name clang-scan-deps-20 earlier than for name clang-scan-deps. For that reason, the result of the search will be /usr/bin/clang-scan-deps-20, and not the expected /opt/my_own_clang_build/bin/clang-scan-deps.
Please let me know whether you agree that this is a bug, and whether the proposed fix looks all right to you.