github / github/codeql

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

Aberta
#13,994 13 comentários 0 reações 0 responsáveis Ver no GitHub
question
Linguagem predominante
CodeQL
Estrelas
10.1k
Forks
2.1k
Merge médio
2d 15h
PRs com merge (30d)
141

Descrição

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

Guia de contribuição

Abrir o guia de contribuição

Direção de pesquisa

Reproduce the database build with run_build_tool.bat and inspect codeql-db/log/build-tracer.log, focusing on the reported diagnose_duplicate_capture assertion in FirstPersonTemplateGameMode.cpp. Run the supplied FunctionCall query against the resulting database and compare it with the extractor errors. Done means the Unreal project is processed without the catastrophic extractor failure and the database contains the expected C++ constructs.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
cpp
Domínio
compilers, tooling
Tipo de issue
Bug
Dificuldade
4/5
Tempo estimado
3-5 dias
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
35/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.