[Driver][HIP/SPIRV] Fix crash when llvm-link is executed. (#196074)
There is a design limitation (see
[InputInfo](https://github.com/llvm/llvm-project/blob/f08b4fff52cdd3fc8fdd962080da089497c00fcc/clang/include/clang/Driver/InputInfo.h#L23))
that is forwarding flags to `llvm-link` when it shouldn't happen. This
commit fixes this issue by sanitizing the arguments forwarded to
`llvm-link`.
This may happen when `clang-linker-wrapper` eventually calls `clang`,
which adds the `-Xlinker` flags. Crash reproducer is here:
https://gcc.godbolt.org/z/rxvWcvan3.
The fix is based on @MrSidims' old PR (#183492).
The error started manifesting by default after the switch to the new
driver, and the issue has been in the new driver since commit
https://github.com/llvm/llvm-project/commit/4c6f398b866030c17fd94dcdca04f4df03c5214c.
However, the problem could potentially be triggered by any call to
`clang`, regardless of the `clang-linker-wrapper`.
---------
Co-authored-by: Dmitry Sidorov <18708689+MrSidims@users.noreply.github.com>