[clang] [clang][scan-build] Treat --use-cc and --use-c++ as shell commands (PR #131932)

Florian Ragwitz via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 19 12:49:25 PDT 2025


rafl wrote:

Thanks for your feedback, Balázs!

> When I looked at this patch and I had the impression that `CCC_CXX` is basically what one should use as `CXX` or `CMAKE_CXX_COMPILER`, which is just a path to a binary - without any arguments.

The author of the original code this change is modifying seemed to make the same assumption, but I believe this is not true. All of the following treats CC/CXX as a command with potential arguments:

```
CC="ccache gcc" ./configure
make CC="ccache gcc"
CXX="ccache g++" cmake ...
```

`CMAKE_<LANG>_COMPILER` also [supports potential arguments](https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER.html):

```
cmake ... -DCMAKE_C_COMPILER='qcc;--arg1;--arg2'
```

The fact that all of these tools will consult `PATH` to resolve the compiler executable when it's not a fully-qualified path further supports that it's a command as opposed to a path to an executable.

> This patch would turn it into a combination of what other tools interpret as `CXX` and `CXX_FLAGS`, did I get this right? This would mean we would deviate from the conventions of other tools, making it less ergonomic.

Your understanding of what the proposed change does is correct. However, most if not all common build tools I've worked with treat these kinds of options as commands, and that's what users seem to expect as well, as per #26594.

This behaviour is very ergonomic, especially when you're truly swapping out the "compiler", such as when replacing "gcc" with "ccache gcc" or similar, without having to write wrapper executables, which is what's currently required by `scan-build` in these situations. In many situations it's possible to achieve the same goal using a combination of `CC` and `CFLAGS`, but this is often less desirable as it can quickly run into issues with accidentally overwriting `CFLAGS` from other sources or having to merge multiple `CFLAGS` correctly.

> If we don't currently have a way to pass extra `CXX` flags, we should consider adding something like that instead of hacking the `CCC_CXX` option. WDYT?

To me, following the established convention of `CC`/`CXX` being commands as opposed to paths to executables seems like the most straightforward approach, but I'm certainly open to alternatives if you see any practical downsides to this.

https://github.com/llvm/llvm-project/pull/131932


More information about the cfe-commits mailing list