<div dir="ltr">Hi Chris,<div><br></div><div>Thx for looking into this. The use case I was thinking about for a while was: </div><div>Can we add clang-tidy to the linters run during <font face="monospace">arc diff </font><font face="arial, sans-serif">to check my modifications, so similar </font>to clang-format?</div><div><br></div><div>A couple of thoughts around that.</div><div><ul><li>Only trigger this linter if the user enabled it (at least until we know it works well). So we would need some mechanism to enable/disable this per user.</li><li>Ensure we have a compile_commands.json and the include files were generated. I suppose this is what your script takes care of.</li><li>Check only the modified files (everything else would be too slow) and filter the findings to your modified lines only. This is covered by <font face="monospace">clang-tidy-diff.py</font></li><li><font face="arial, sans-serif">I don't know if we want to offer to apply fix-its at this point. They might be too noisy.</font></li></ul></div><div>What do you think?</div><div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Best,<div>Christian</div></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Dec 16, 2021 at 7:46 AM Chris Sears via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-size:small"><div class="gmail_default">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.<br><br>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.<br><br>tidy-llvm XXAsmPrinter.cpp generates a clang-tidy command line that looks like:<br><br>  clang-tidy -checks="llvm-*" -p .../build XXAsmPrinter.cpp -- -I.<br>    -IAsmParser -IGISel -IDisassembler -ITargetInfo -IXX -IMCTargetDesc<br>    -I.../libcxx/include -I.../build/include -I.../llvm/include<br><br>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.<br><br>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):<br><br>  Error while processing path to XXAsmPrinter.cpp.<br>  path/libcxx/include/__config:13:10: error: '__config_site' file not found [clang-diagnostic-error]<br>  #include <__config_site><br><br>__config_site is indeed not in my build tree. There is a file libcxx/include/__<a href="http://config_site.in/" target="_blank">config_site.in</a> but that's it. Again, someone more knowledgable in the build machinery might understand why this is the case.<br><br>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.<br><br>Adding support for run-clang-tidy would be nice but for tidying individual files it really won't matter.</div><div class="gmail_default"><br></div><div class="gmail_default"><a href="https://reviews.llvm.org/D115848" target="_blank">https://reviews.llvm.org/D115848</a></div></div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>