github / github/codeql

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

Aperta
#13,994 13 commenti 0 reazioni 0 assegnatari Vedi su GitHub
question
Lingua principale
CodeQL
Stelle
10.1k
Fork
2.1k
Merge medio
2g 15h
PR unite (30g)
141

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.