# properly annotate nullability of ZigLLVMCreateDebugForwardDeclType · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/cdb40936bd528ee92dd11cf090ab75cf08bc0fc0)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: cdb40936bd528ee92dd11cf090ab75cf08bc0fc0

Requested commit: cdb40936bd528ee92dd11cf090ab75cf08bc0fc0

Commit: cdb40936bd528ee92dd11cf090ab75cf08bc0fc0

Tree: a31dd11ee8cd3ca9d244f788c82e8f5c61939657

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

````
properly annotate nullability of ZigLLVMCreateDebugForwardDeclType

This bug manifested as a segfault in stage1 when calling this function.
The C++ code looks like this:

```c++
entry->llvm_di_type = ZigLLVMCreateDebugForwardDeclType(g->dbuilder,
    ZigLLVMTag_DW_structure_type(), full_name,
    import ? ZigLLVMFileToScope(import->data.structure.root_struct->di_file) : nullptr,
    import ? import->data.structure.root_struct->di_file : nullptr,
    line);
```

There is actually no problem here - what happened is that because
cross-language LTO was enabled between zig and c++ code, and because
Zig annotated the file parameter (3rd line) as being non-null, the C++
code assumed that parameter could not be null, and eagerly dereferenced
`import->...`, causing a segfault, since it was null.

I verified that this commit fixed the problem and I also verified this
hypothesis by disabling LTO and noticing that it indeed avoided the
problem.

````

## Parents

- [d31be31267523cadd6d59b52633f2d4a9758a3b4](https://git.cafe/gitcafe/zig/commit/d31be31267523cadd6d59b52633f2d4a9758a3b4?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/cdb40936bd528ee92dd11cf090ab75cf08bc0fc0?format=markdown)
