[llvm-dev] RFC tidy-llvm.py

Mehdi AMINI via llvm-dev llvm-dev at lists.llvm.org
Thu Dec 16 00:20:50 PST 2021


Even without symlink, after running CMake in my `build/` folder, clang-tidy
seems to just work for me, from the LLVM monorepo root:

$ clang-tidy -p build/ llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
21470 warnings generated.
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:196:39: warning: invalid case
style for parameter 'tm' [readability-identifier-naming]
AsmPrinter::AsmPrinter(TargetMachine &tm, std::unique_ptr<MCStreamer>
Streamer)
                                      ^~
                                      Tm
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:973:14: warning: invalid case
style for variable 'ignored' [readability-identifier-naming]
        bool ignored;
             ^~~~~~~
             Ignored
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:2029:27: warning: invalid case
style for parameter 's' [readability-identifier-naming]
    SectionCPs(MCSection *s, Align a) : S(s), Alignment(a) {}
                          ^               ~
                          S               S
[...]



On Wed, Dec 15, 2021 at 11:34 PM David Blaikie via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Can you use a compilation database? Generate one from your LLVM build
> tree, symlink it into the root of your source tree & I'd think clang-tidy
> would find it there & use it & should be good to go?
>
> On Wed, Dec 15, 2021 at 10:46 PM Chris Sears via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
>
>> Using clang-tidy on LLVM itself (the proverbial eating your own dogfood)
>> is a little different from using a clang-tidy installation on another
>> source tree. clang-tidy needs to know where to find include files within
>> the LLVM source tree itself.
>>
>> This is a Python script, tidy-llvm, which finds the root of the llvm
>> tree, verifies LLVM build requirements
>> (LLVM_ENABLE_PROJECTS:STRING=clang;clang-tools-extra and
>> CMAKE_EXPORT_COMPILE_COMMANDS:UNINITIALIZED=On), constructs llvm and
>> current directory include paths, concatenates up an argument list and then
>> runs clang-tidy on the .h and .cpp files on the command line.
>>
>> tidy-llvm XXAsmPrinter.cpp generates a clang-tidy command line that looks
>> like:
>>
>>   clang-tidy -checks="llvm-*" -p .../build XXAsmPrinter.cpp -- -I.
>>     -IAsmParser -IGISel -IDisassembler -ITargetInfo -IXX -IMCTargetDesc
>>     -I.../libcxx/include -I.../build/include -I.../llvm/include
>>
>> I'm pretty sure that the llvm include directories (-I.../libcxx/include
>> -I.../build/include -I.../llvm/include others?) have to be enumerated
>> rather than simply inheriting where clang-tidy thinks they are in the
>> installation. Unless I manually specified them, clang-tidy wasn't finding
>> them.
>>
>> I think someone more expert in the build machinery could improve it
>> greatly. For example, it currently gets a strange error about __config_site
>> (which doesn't prevent the rest of the clang-tidy checking):
>>
>>   Error while processing path to XXAsmPrinter.cpp.
>>   path/libcxx/include/__config:13:10: error: '__config_site' file not
>> found [clang-diagnostic-error]
>>   #include <__config_site>
>>
>> __config_site is indeed not in my build tree. There is a file
>> libcxx/include/__config_site.in but that's it. Again, someone more
>> knowledgable in the build machinery might understand why this is the case.
>>
>> clang-tidy still interprets its .clang_tidy file wherever it finds it.
>> It's better to leave most of the -checks there. The tidy-llvm Python script
>> itself is currently set to -checks=\"llvm-*\". I set modernize in the
>> .clang_tidy file for my backend. I can imagine having a .clang-tidy file at
>> the root of the llvm tree.
>>
>> Adding support for run-clang-tidy would be nice but for tidying
>> individual files it really won't matter.
>>
>> https://reviews.llvm.org/D115848
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>
> _______________________________________________
> 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/20211216/bbb1e61f/attachment.html>


More information about the llvm-dev mailing list