<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/78344>78344</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [AMDGPU] clang misreports HIP installation path as `/usr/local` when it is installed in `/usr`.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          AngryLoki
      </td>
    </tr>
</table>

<pre>
    clang misreports HIP installation path as `/usr/local` when it is installed in `/usr` (in Gentoo).

Context: CMake calls `clang -v -print-targets` to get get HIP/ROCm root: [CMakeDetermineHIPCompiler.cmake#L151](https://github.com/Kitware/CMake/blob/v3.28.1/Modules/CMakeDetermineHIPCompiler.cmake#L151)

```
$ clang -v -print-targets -print-rocm-search-dirs 
clang version 17.0.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm/17/bin
Configuration file: /etc/clang/x86_64-pc-linux-gnu-clang.cfg
System configuration file directory: /etc/clang
Selected GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/13
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
ROCm installation search path: /usr/lib/llvm/17
ROCm installation search path: /usr/lib/llvm/17
ROCm installation search path: /usr/lib/llvm/17/bin/../../../../lib/clang/17
ROCm installation search path: /opt/rocm
ROCm installation search path: /usr/local
ROCm installation search path: /usr
Found HIP installation: /usr/local, version 5.7.31921
...
```

Meanwhile, `/usr/local` is empty ([docs](https://devmanual.gentoo.org/general-concepts/filesystem/index.html))
```sh
$ du /usr/local
0       /usr/local/bin
0       /usr/local/lib
0 /usr/local/sbin
0       /usr/local/lib64
0 /usr/local
```

In Gentoo HIP/ROCm is installed into `/usr`. Version file is installed into `/usr/share/hip/version`. HIP runtime is detected by 
https://github.com/llvm/llvm-project/blob/bbb3f9b1321176a012dac7d50da54b869a85e9bc/clang/lib/Driver/ToolChains/AMDGPU.cpp#L478-L492
It checks ROCm installation search paths, at some point it checks `/usr/local` (before `/usr`), then according to the code finds `/usr/local/../share/hip/version` and completes the search.

I examined clang code and I don't see any way to manipulate clang to report the correct path. There is `ROCm installation search path: /usr`, but it is: 1) checked after `/usr/local` and 2) checked by trying to find a file `/usr/../share/hip/version`, which does not exist.

I'm aware that it is possible to patch CMakeDetermineHIPCompiler.cmake or set env vars HIP_PATH, ROCM_PATH, etc, but I want to see correct path detection out-of-the-box without patches or extra environment variables (maybe with CMake option like `-DCLANG_ROCM_DIR=/usr` for Gentoo Clang maintainer).

Could you revisit ROCm detection code and provide any solution? Thanks!
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEV11v2zoS_TX0y8CCRNmy_eAH14ZaY5u9QTe7rwVFji1uKFIgKcf-9wuScj4aN_fmZW_RKFA4MxwenjkzYs7Jo0Zck_kXMt9N2OBbY9cbfbSX7-ZRThojLmuumD5CJ53F3ljv4Nv-HqR2ninFvDQaeuZbYA5IlRNaD84SWivDmSJVDk8tapAepLs6oQCpXxlXORC6lBq-ovbGELrKSL4j-SY9t0Z7PHtSbmB7xx4ROFMqbpYym55g2lup_dQze0TvQkBv4Ig-_nzb3xNa__hj24E1JsYh8y8x1A492k5q_La_35qulwptxjv2iISW34t5QeY7Qpet970j5YbQmtD6KH07NBk3HaH1P6R_YhYJrWNAQutGmYbQ-lRmdJkVhNZ3RgwK3dXkz_ekq9fHDzil_-mVzuA3576-WsO7qUNmeTsV0jpInsnrhNaFOysWWZ5VaeUh-gdgzsvqZzWb9nyqpB7O06MeRpPWIhPQGYEqGPbGyXNa2l9vdSdtBPeZAjIAodQpAFUsAjZSP9_pQR4Hm_hzkApHT_Sc0DqmSmh9I51pXMv44Zgi_eviPHbA3wUEIS1yb-zlRujkigq5RwFft9s3hL5xiiPnt_MJRyvHQzEtpGAeoRuUl8Gx3EBGyi9klnfV7COrko5mJf0luY9iRVK_KcV07bEiP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