[clang-tools-extra] [clang-tidy] New option `CompilationArgsToRemoveRegex` to remove arguments from the command line (PR #111453)
FĂ©lix-Antoine Constantin via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 22 09:40:05 PST 2024
felix642 wrote:
> If I understand correctly, this situation is when CMake is configured for another compiler (e.g., GCC) but is also instructed to run clang-tidy, but then CMake hands clang-tidy the command line arguments it was handing to GCC, and clang-tidy is giving hard errors for the unknown command line arguments.
Exactly. This option was added to handle this situation similarly to what Clangd already does. They currently have an option `Remove` (https://clangd.llvm.org/config.html#remove) which removes arguments from the command line before compiling the source file.
Currently, clang-tidy only supports adding arguments through the `ExtraArgs` options, but does not allow removing arguments and the user either has to add conditional statements to allow only flags recognized by Clang when running CMake or postprocess the compile_commands.json file to remove those unknown flags.
I think the ideal solution would be to support this feature directly with the build system as highlighted by @carlosgalvezp and maybe add an option to clang-tidy as suggested by @nicovank `--ignore-unknown-flags` to allow clang-tidy to run with unrecognized flags.
I have added the argument in clang-tidy since this was fairly simple to support and was already in line with what was done in other tools (Clangd). I don't mind having a more in-depth look into the clang's codebase to see how those unknown arguments could be handled directly by the build system.
https://github.com/llvm/llvm-project/pull/111453
More information about the cfe-commits
mailing list