github / github/codeql

C++ extractor fails to process code based on Unreal Engine

オープン
#13,994 コメント 13 件 リアクション 0 件 担当者 0 名 GitHub で見る
question
主要言語
CodeQL
スター
10.1k
フォーク
2.1k
平均マージ
2日 15時間
マージ済み PR(30日)
141

説明

Hey team,

I am trying to build a CodeQL database for a [sample](https://docs.unrealengine.com/4.27/en-US/Resources/Templates/FirstPerson/) Unreal project. Building the code base on Unreal Engine includes two main steps:

1. Running [`UnrealHeaderTool`](https://docs.unrealengine.com/4.27/en-US/ProductionPipelines/BuildTools/UnrealHeaderTool/) that parses the C++ headers for Unreal-related class metadata and generates custom C++ code.
2. Running the normal C++ compiler to compile the generated code.

Unreal Engine also has `UnrealBuildTool` that runs the above steps.

I use the following command to build the CodeQL database:

```
codeql database create --language=cpp --overwrite --command=run_build_tool.bat -- codeql-db
```

where `run_build_tool.bat` contains this:

```
"c:\Program Files\Epic Games\UE_4.27\Engine\Binaries\DotNET\UnrealBuildTool.exe" FirstPersonTemplate Win64 Development -Project=d:\projects\codeql\unreal\FirstPersonTemplate\FirstPersonTemplate.uproject -log=build.log
```

The `codeql database create ...` command finishes successfully. The `codeql database print-baseline codeql-db` shows about 3K lines of C++ code. The following query returns a list of files included into the database:

```
import cpp

from File f
select f, "file"
```

However, the database doesn't not include any function call, if-blocks, etc although the code have them. For example, the following query doesn't return anything:

```
import cpp

from FunctionCall call
select call, "function call"
```

I see multiple errors in `build-tracer.log` like this:

```
CodeQL C++ extractor: Current location: E:\projects\unreal\FirstPersonTemplate\Source\FirstPersonTemplate\FirstPersonTemplateGameMode.cpp:507675,0
CodeQL C++ extractor: Current physical location: E:\projects\unreal\FirstPersonTemplate\Source\FirstPersonTemplate\FirstPersonTemplateGameMode.cpp:17,0 (end of source)
Internal error: assertion failed at: "class_decl.c", line 33485 in diagnose_duplicate_capture

[E 16:25:56 12932] Warning[extractor-c++]: In construct_message: Internal error: assertion failed at: "class_decl.c", line 33485 in diagnose_duplicate_capture

1 catastrophic error detected in the compilation of "E:\projects\unreal\FirstPersonTemplate\Source\FirstPersonTemplate\FirstPersonTemplateGameMode.cpp".
Compilation aborted.
```

Does it look like a bug in the C++ extractor, or am I doing anything wrong?

Steps to reproduce:
1. [Install Unreal Engine 4](https://docs.unrealengine.com/4.27/en-US/Basics/InstallingUnrealEngine/)
2. [Create a sample first-person project](https://docs.unrealengine.com/4.27/en-US/Resources/Templates/FirstPerson), select C++ instead of Blueprint
3. Build a CodeQL database as described above
4. Check errors in `codeql-db/log/build-tracer.log`
5. Run the query above that looks for function calls

My testing environment:
* CodeQL CLI v2.14.2
* Windows 10 x64
* Visual Studio 2019 toolchain (tested with 2022 -- same results)
* Unreal Engine 4.27

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

run_build_tool.bat でデータベースのビルドを再現し、codeql-db/log/build-tracer.log を調査して、FirstPersonTemplateGameMode.cpp で報告されている diagnose_duplicate_capture assertion に重点を置きます。提供されている FunctionCall クエリを生成されたデータベースに対して実行し、extractor のエラーと比較します。Unreal プロジェクトが catastrophic extractor failure なしで処理され、データベースに期待される C++ 構造が含まれていれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
cpp
領域
compilers, tooling
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。