[llvm-dev] clang-tidy standalone

martin lampacher via llvm-dev llvm-dev at lists.llvm.org
Fri Jul 5 14:00:29 PDT 2019


Hello Don,

thanks a bunch for the reply! Yeah I was looking deeper into it - and it makes sense. Apart from naming lot of the checks do require the actual build/AST. I'm working on that now - compiledb might just do what I need otherwise building the file should not be a major problem.

Am I correct in assuming that the compile database should contain _all_ the files that are required for a build, whereas I can still run clang-tidy on a per-file basis? We have loads of third-party code that needs to be configured and compiled into our projects but must not be modified (safety project).

I hope it is o.k. if I'm continuing to post here. It's hard to find references on the web for this kinda edge-case, otherwise just let me know :)

Cheers.M

> On 5 Jul 2019, at 19:13, Don Hinton <hintonda at gmail.com> wrote:
> 
> 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://clang.llvm.org/docs/JSONCompilationDatabase.html>
>   https://github.com/nickdiego/compiledb <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 <mailto: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 <mailto:llvm-dev at lists.llvm.org>
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev <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/9ae8403c/attachment.html>


More information about the llvm-dev mailing list