[cfe-dev] [llvm-dev] clang-tidy standalone

Don Hinton via cfe-dev cfe-dev at lists.llvm.org
Fri Jul 5 14:18:31 PDT 2019


First, let me move this over to cfe-dev -- that's where the clang-tidy
developers hang out.

On Fri, Jul 5, 2019 at 4:00 PM martin lampacher <lmapii at googlemail.com>
wrote:

> 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'm not sure exactly how cmake decides what to include in the compilation
database, but I'd assume it includes anything that clang compiles, which is
all you're concerned with.  As for 3rd party code, you can pick up the
headers automatically (please see --header-filter=), but if you want the
c/cpp files, you need to do each project individually.  Just try a few, and
you'll figure it out pretty quickly.

hth...
don

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://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/cfe-dev/attachments/20190705/6fe4b066/attachment.html>


More information about the cfe-dev mailing list