github / github/codeql

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

Đang mở
#13,994 13 bình luận 0 reaction 0 người được giao Xem trên GitHub
question
Ngôn ngữ chính
CodeQL
Star
10.1k
Fork
2.1k
Merge trung bình
2 ngày 15 giờ
Pull request đã merge (30 ngày)
141

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.