Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Make your and other programmers' life easier wi...

Make your and other programmers' life easier with static analysis (Unreal Engine 4)

The PVS-Studio team talks about how to use static analysis to look for code errors in the Unreal Engine 4 game engine.
Here are our results of checking Unreal Engine 4 with PVS-Studio: https://pvs-studio.com/en/blog/posts/cpp/0517/

PVS-Studio

July 06, 2023
Tweet

More Decks by PVS-Studio

Other Decks in Programming

Transcript

  1. Make Your and Other Programmers’ Life Easier with Static Analysis

    (Unreal Engine 4) George Gribkov pvs-studio.com
  2. 1. What is static analysis and what is it for?

    2. How does static analysis work? (Unreal Engine 4) 3. How to introduce static analysis into your project: best practices Contents 2
  3. ▪ Programmers miss bugs ▪ QA Engineers spend time to

    find them ▪ Programmers spend time to fix them ▪ Cost to fix bugs rises rapidly Challenges 5
  4. ▪ Integer overflow caused the explosion ▪ Rocket carried four

    satellites ▪ Losses amounted to $ 370 000 000 Example of a Very Expensive Error 13
  5. ▪ Unit testing ▪ Integration testing ▪ System testing ▪

    … ▪ Dynamic analysis ▪ Static analysis Ways to Find Errors 14
  6. ▪ Static analysis tools: check code when it’s not executed

    ▪ Dynamic analysis tools: check code when it’s being executed Automated Code Analysis Tools 15 ▪ Both approaches complement each other very well
  7. 17

  8. ▪ Covers the entire code ▪ Works fast ▪ Is

    convenient for all sizes of projects ▪ Saves programmers’ time ▪ Saves QA Engineers’ time Static Analysis Pros 18
  9. Modern Static Analysis Tools 19 • PVS-Studio • ReSharper •

    Coverity • SonarQube • Klocwork • Clang Static Analyzer • IntelliJ IDEA • And others
  10. ▪ My boss found errors in UE 4 and wrote

    an article ▪ The developers of Epic Games liked the article a lot ▪ They wanted to fix more errors and entrusted it to us How It Started 22
  11. ▪ The most convenient way: check the project via Visual

    Studio ▪ It’s great that UE has a set of scripts for .vcxproj- files The First Check 24
  12. 1.Generate project files 2.Build the project 3.Start the analysis via

    Visual Studio 4.??????? 5. The First Check 25
  13. 1.Generate project files 2.Build the project 3.Start the analysis via

    Visual Studio 4.??????? 5. EPIC GAMES FAIL The First Check 26
  14. ▪ Generated project files are just wrappers ▪ These wrappers

    call the Unreal Build Tool ▪ Unreal Build Tool calls cl.exe (or clang for Linux builds) ▪ The analyzer cannot collect the parameters required for compilation because of all these layers Unreal Engine Build System 27
  15. ▪ What if we try to find compiler calls directly?

    ▪ We’re lucky to have a special utility to monitor compilation The Second Check 29
  16. 1.Start the compilation monitoring utility before building the project 2.The

    utility builds all the necessary data 3.Right after the build, run the analysis 4.??????? 5. The Second Analysis Attempt 30
  17. The Second Analysis Attempt 31 1.Start the compilation monitoring utility

    before building the project 2.The utility builds all the necessary data 3.Right after build run the analysis 4.??????? 5. EPIC WIN!!!
  18. Analysis Results ▪ 1192 top level warnings (Level 1) ▪

    629 second level warnings (Level 2) ▪ 1821 warnings in total (without Level 3) 33
  19. 34

  20. ▪ At night we built the final version of UE

    4 ▪ We analyzed each build ▪ In the morning, we got a new report with errors found ▪ What’s more, we could check the build right away How We Fixed Bugs 39
  21. The Number of Warnings 41 0 5 10 15 20

    25 1 2 3 4 5 Warnings 0 5 10 15 20 25 1 2 3 4 5 Warnings ▪ Expectation ▪ Reality
  22. ▪ The developers of Epic Games were pleased ▪ They

    started using a continuous static code analysis, as we did ▪ Now they receive warnings about errors promptly ▪ As for us… we wrote another article :) Results 43
  23. ▪ Run the analysis in the early stages ▪ Run

    the analysis regularly Two Main Approaches 45
  24. ▪ May be used locally on developers’ computers (plugins for

    IDEs, compilation monitoring system) Introducing Static Analysis 49
  25. ▪ May be used in Continuous Integration Systems (command- line

    utilities, CI-system plugins, monitoring systems) Introducing Static Analysis 50
  26. ▪ Hide old errors and work as usual ▪ Starting

    that moment you’ll get only new warnings ▪ Work on errors in new code only ▪ Don’t forget about hidden errors! Get back to them and fix one-by-one. How to Work with Suppress Files 54
  27. ▪ A very convenient method is a “ratchet mechanism” ▪

    Suppress file is committed to the version control system ▪ Changes are allowed only if they don’t increase warnings total number How to Work with Suppress Files 55
  28. ▪ NO ▪ The best approach: static + dynamic analysis

    Should I Use Static Analysis Only? 59