Static Code Analysis

Unreal Build Tool supports running a variety of static code analyzers.

Choose your operating system:

Windows

macOS

Linux

Unreal Build Tool (UBT) supports running several different static code analyzers. Static Code Analyzers use a variety of algorithms and techniques to inspect source code and find bugs without executing the code. This means faster analysis, earlier detection of memory leaks and logic errors, and reduced technical debt.

Use a Static Code Analyzer with UBT

The general command-line syntax for running a static code analyzer with UBT from your Unreal Engine root directory is:

Engine\Build\BatchFiles\RunUBT.bat TARGET PLATFORM Development -StaticAnalyzer=ANALYZER

TARGET, PLATFORM, and ANALYZER are required arguments in the above command you must replace with your desired values.

  • TARGET: A build target supported by UBT, see the documentation on Targets for more information.

  • PLATFORM: A platform supported by Unreal Engine. Visit the General Platform Support pages to learn about Unreal Engine platform support.

  • ANALYZER: A static code analyzer that UBT uses to analyze the provided target on the designated platform. Refer to the Supported Analyzers section below to view the available options.

Supported Analyzers

Analyzer

Description

Default

Default static analyzer for the selected compiler (if it has one).

VisualCpp

Built-in Visual C++ static analyzer. Only supported for Microsoft Visual C++ (MSVC) based platforms.

PVSStudio

PVS-Studio static analyzer. Only supported for MSVC-based platforms.

PVS-Studio requires a license file placed next to the installed PVS-Studio.exe executable. For more information about PVS-Studio and obtaining a license, visit the PVS-Studio documentation.

Clang

Clang static analyzer. This forces the compiler to Clang for MSVC-based platforms.

The Clang static analyzer is in Beta. Features available in Beta state give you the opportunity to learn how they work, plan your pipeline, and create test content. You should use caution when using these features in production, as we are still working to get to shipping-quality performance, stability, and platform support. We support backward compatibility for assets, and the APIs for these features are stable.

Examples

Run the following command from your Unreal Engine root directory to use the default static code analyzer with Unreal Editor as the target on a Windows 64-bit platform:

Engine\Build\BatchFiles\RunUBT.bat UnrealEditor Win64 Development -StaticAnalyzer=Default

Run the following command from your Unreal Engine root directory to use the Visual C++ static code analyzer with the Lyra Starter Game as the target on a Windows 64-bit platform:

Engine\Build\BatchFiles\RunUBT.bat LyraGame Win64 Development -StaticAnalyzer=VisualCpp

Command-line Options for Clang Analyzer

Option

Description

-StaticAnalyzerOutputType=html

Writes out web pages with navigation that describe the analysis warnings. These HTML files are written into the appropriate folders within the Engine/Intermediate/Build directory for the selected platform and target.

-StaticAnalyzerMode=shallow

Enables shallow analysis. This means analysis completes more quickly, but is less informative than standard analysis. We do not recommend using this mode for general purposes.

-StaticAnalyzerChecker=CHECKER

Provides a list of static analyzer checkers that you want to enable rather than the default list.

-StaticAnalyzerDisableChecker=CHECKER

Disables static analyzer default checkers. This option overrides the default disabled checkers which are deadcode.DeadStores and security.FloatLoopCounter. This option is unused if -StaticAnalyzerChecker is set.

-StaticAnalyzerAdditionalChecker=CHECKER

Enables additional non-default static analyzer checkers. This option is unused if -StaticAnalyzerChecker is set.

For a full list of Clang analyzer checkers, see Available Checkers in the Clang documentation.