Skip to content

Comparison with "clang‐tidy for Unreal Engine"

June Rhodes edited this page Jul 29, 2024 · 6 revisions

Previously we offered a product called "clang-tidy for Unreal Engine" as a commercial subscription, which hooked into the Unreal Engine build process and ran a modified version of clang-tidy for each C++ file in your project.

This project fully replaces clang-tidy for Unreal Engine. If you're still using that product under a free or custom license, we recommend switching to this fork of Clang instead. It's much faster than clang-tidy for Unreal Engine, and is actively maintained.

"clang-tidy for Unreal Engine" was slow

The "clang-tidy for Unreal Engine" project worked by adding additional commands to the action graph, which meant that you'd parse your C++ code twice - once under MSVC, and a second time for clang-tidy to run. The compilation time impact of this meant our larger paying customers of "clang-tidy for Unreal Engine" generally ended up licensing it to only run on build servers, as it was too slow to run on developer machines.

Not only does this mean that we weren't licensing it at at a scale to dedicate resources to supporting/maintaining it, but it was also far less ideal as a development experience for our customers - for a developer working on C++ code, finding out that you have a regression on an overnight build is a much poorer development experience that finding out immediately as you're developing on your local machine.

"clang-tidy for Unreal Engine" was brittle

In order to add additional commands to the Unreal Engine action graph, the "clang-tidy for Unreal Engine" project would patch UnrealBuildTool. Whenever Epic made changes to UnrealBuildTool, the patches were liable to break. This meant that we had to maintain not only our changes to clang-tidy, but also update our patching code for each new engine version.

In contrast, this fork of Clang/LLVM executes and appears like the normal version of Clang to UnrealBuildTool. No patches or changes need to be made to any of the Unreal Engine build infrastructure for it to work, which makes it work with any engine version, and we don't have to worry about changes that Epic Games makes.

Modifying Clang/LLVM to do custom static analysis directly

With these issues in mind, the only solution to this problem was to integrate the static analysis directly into the Clang compiler itself.

Rather than a separate action graph step, you configure your project to build with Clang, and this fork runs the static analysis in between Clang parsing the C++ code and performing LLVM codegen. It gets to re-use the AST that Clang already needs to parse for compilation, it is able to run the static analysis rules in parallel, and it runs them only for the files you want. This makes it much much faster than clang-tidy (Performance goes into more detail on this).

As an additional benefit, although this fork of Clang/LLVM is modified to understand the Unreal Engine UCLASS/etc specifiers, it can also be used with general C++ projects. You don't need to be working on Unreal Engine code to get the benefit of this fork - any C++ project can leverage .clang-rules files for custom static analysis.