1

I'm trying to run clang-tidy on my IAR project, but I would like to ignore system header files. I tried the solutions provided here but they didn't work (read on for the results). Here's my project structure:

Proj
----Src
----Inc
SysHdrs

And this is my clang-tidy command from inside Proj:

clang-tidy.exe Src/*.c -header-filter=Proj\\Inc\\.* -checks=* -- -I"abs/path/to/Proj/Inc" -isystem"abs/path/to/SysHdrs"

I'm getting warnings on my Src files, as well as on some SysHdrs files such as SysHdrs/DLib_Defaults.h and SysHdrs/yvals.h. For example:

abs/path/to/SysHdrs/DLib_Defaults.h:563:6: error: "Compiler must support __weak" [clang-diagnostic-error]
    #error "Compiler must support __weak"
     ^
abs/path/to/SysHdrs/yvals.h:37:4: error: "DLib compiled with wrong (version of IAR) compiler" [clang-diagnostic-error]
  #error "DLib compiled with wrong (version of IAR) compiler"
   ^
abs/path/to/SysHdrs/yvals.h:232:11: error: unknown type name '__WCHAR_T_TYPE__' [clang-diagnostic-error]
  typedef __WCHAR_T_TYPE__ _Wchart;

abs/path/to/SysHdrs/yvals.h:358:3: error: expected identifier or '(' [clang-diagnostic-error]
  __WEAK __ATTRIBUTES void __iar_Locksyslock_Malloc(void);
  ^

Note that I do need to supply the system headers to clang, because otherwise it'd complain about a missing stdio.h / string.h etc.

As far as I know the -header-filter should filter out whatever doesn't match the regex pattern, so my system headers shouldn't be included in the outuput. Further, I've explicitly set the SysHdrs as "system headers" by using the -isystem identifier.

I even tried -header-filter=main\.h and it still processes the system headers.

Anything else I can try?

Alaa M.
  • 4,961
  • 10
  • 54
  • 95
  • i used a little different syntax, maybe try: `-isystem abs/path/to/SysHdrs`; I used cmake and at the end i ended in CMakeLists.txt with `include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/dependencies/include)` because of his the gcc compiled this as system headers. i am not quite sure, but maybe cmake create all that is needed. Can't find it now – Chris Nov 15 '21 at 19:58
  • @Chris - Got it, thanks, – Alaa M. Nov 16 '21 at 06:58
  • what was the solution or error? maybe also solve your own question with an answer – Chris Nov 16 '21 at 11:56
  • @Chris - I haven't solved it yet. – Alaa M. Nov 16 '21 at 13:38

0 Answers0