[llvm-dev] clang-tidy standalone

Don Hinton via llvm-dev llvm-dev at lists.llvm.org
Fri Jul 5 10:13:57 PDT 2019


Hi Martin:

Clang-tidy works on the AST, so you have to be able to compile the program
and produce a valid AST for it to do anything useful.

Here are a few things you can try:

1) Don't pass -DCMAKE_EXPORT_COMPILE_COMMANDS=On to clang-tidy:
  This only works when passed to cmake when generating build files, e.g.,
Makefiles.  So if you aren't using cmake, you'll need to generate the
compilation database yourself.  Google for it, and you'll find a bunch of
links, but here's a couple that might be useful (note I haven't used them):

  https://clang.llvm.org/docs/JSONCompilationDatabase.html
  https://github.com/nickdiego/compiledb

  Then use the -p flag to help clang-tidy find and use it -- it's just a
json file.

2) You can also pass additional flags after the --, e.g., -I, etc. if
needed.

hth...
don


On Wed, Jul 3, 2019 at 6:11 PM martin lampacher via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Hello,
>
> sorry for posting this here but I'm kind of stuck. I'm trying to introduce
> LLVM tooling step by step at the company I'm working for. So far I'm using
> clang-format for automated formatting.
>
> Since I'm also working on the coding guideline I wanted to use clang-tidy
> for enforcing the naming convention. The problem is that we're using a
> plain old MAKE project, so I can't really benefit from the CMAKE
> integration.
>
> The idea was to simply run clang-format and clang-tidy alongside the
> normal MAKE process, it's quite easy to integrate into the ruleset.
>
> With clang-tidy I have the problem that it is trying to do "to much". So
> even if I'm disabling all rules but 'readability-identifier-naming ' the
> tool will still execute clang-diagnostic-error checks.
>
> Full example:
>
> *dummy.c*
>
> #include "dummy.h"#include "MISSING_module.h"
> // EOF
>
> *dummy.h*
>
> #ifndef _DUMMY_H_#define _DUMMY_H_
> #include <stdlib.h>
> // EOF
>
> I'm trying to execute the following command (macos)
>
> clang-tidy dummy.c -checks='-*,readability-identifier-naming' -- -DCMAKE_EXPORT_COMPILE_COMMANDS=ON`
>
> however, clang-tidy is still checking/following the includes (one of which
> doesn't even exist - but I'm just using it for naming convention checks), I
> get the following error message:
>
> dummy.h:4:10: error: 'stdlib.h' file not found [clang-diagnostic-error]#include <stdlib.h>
>           ^Found compiler error(s).
>
> Is there any way to disable the clang-diagnostic rules?
>
> Cheers,
> Martin
>
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190705/7a513593/attachment-0001.html>


More information about the llvm-dev mailing list