3

I am running an embedded C project based on a tricore-gcc compiler. I made a compile_commands.json file that works well. However, there are some arguments that clang-tidy cannot recognize. For example I get the following

error: unknown argument: '-fstrict-volatile-bitfields' [clang-diagnostic-error]

when I run clang-tidy. This is not a surprise of course, since -fstrict-volatile-bitfields is an option for gcc but not for clang-tidy.
However, I would like to suppress output messages due to unknown compiler options.
I tried to append --extra-arg=-Wno-unknown-warning-option as suggested here but the problem persists.

Barzi2001
  • 989
  • 8
  • 24
  • Just remove the `-fstrict-volatile-bitfields` argument from your `.clang-tidy` file or if you give it as a command line argument to `clang-tidy`. It should be an argument to the compiler, not to `clang-tidy`. – Ted Lyngmo Jun 29 '21 at 11:50
  • You mean `.json` file? I could do that but I have too many arguments and too many files. If there is an option to ignore the compiler arguments not recognized by clang-tidy but that appear in the `.json` file it would be way better. – Barzi2001 Jun 29 '21 at 11:52
  • Yeah, if it's in your `json` file and passed as an argument to `clang-tidy`, remove it. It should be passed to the compiler only. You need to have (at least) one set of options for the compiler and another for `clang-tidy` but `clang-tidy` usually runs without options and reads the nearest `.clang-tidy` config file, so, invoke `clang-tidy` without arguments (except the file to check) to start with. – Ted Lyngmo Jun 29 '21 at 11:54
  • Yes, that would be the best, but the problem relies if there is some file with some specific flag that is recognized by both `clang-tidy` and `gcc`. In that case shall I add it or not to the argument list for `clang-tidy`? And I should I make this check for each single file in the `json`? We are talking of hundreds of `.c` files. – Barzi2001 Jun 29 '21 at 11:59
  • `clang-tidy` usually don't require any flags/options and the flags/options it does recognize are not recognized by `gcc`. I haven't worked with `compile_commands.json` so I don't know to make general rules as in plain old `Makefile`s I'm afraid. – Ted Lyngmo Jun 29 '21 at 12:02
  • It's OK! :) I need `clang-tidy` to parse some flags from the `.json?` file though (for example to specify where some header file is located) :) Let's see if I get some answer. – Barzi2001 Jun 29 '21 at 12:18

1 Answers1

0

I had the same problem when using clang-tidy for a project compiled with GCC. The two compilers have different set of recognized flags. My compile_commands.json, which was generated by intercept-build, contained a number of options used by GCC that clang-tidy did not understand.

I solved this by a somewhat hackish solution of redacting the compile database before initiating the static analysis pass.

My script contains a number of Sed lines similar to this:

sed -i -E 's#-fconserve-stack##g' compile_commands.json
sed -i -E 's#-maccumulate-outgoing-args##g' compile_commands.json
sed -i -E 's#-mindirect-branch-register##g' compile_commands.json
sed -i -E 's#-mindirect-branch=thunk-extern##g' compile_commands.json
sed -i -E 's#-mpreferred-stack-boundary=3##g' compile_commands.json
sed -i -E 's#-mfunction-return=thunk-extern##g' compile_commands.json

This way, the unsupported flags are made invisible to clang-tidy, which allows to work without errors.

Grigory Rechistov
  • 2,104
  • 16
  • 25