<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/54626>54626</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            libclang python: Missing VAR_DECL initializer if NULL present
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          japendergrass
      </td>
    </tr>
</table>

<pre>
    The libclang python bindings are consistently not returning the initializer child cursor for `VAR_DECL` cursors if a `NULL` is present (apparently) anywhere in the initializer. This includes initializing a value to `NULL`, to an array with at least one `NULL` element, or to a structure with a `NULL` field (and seems to apply when these are nested as well). 

Using `((void*)0)` instead of `NULL` does not produce this issue, nor does using `0`.

The following `demo.py` (apologies for not attaching, the github page keeps producing an error when I try) illustrates the issue by dumping the children of a `my_global` variable on several sample C files. 

```
$ for f in *.c; do python ./demo.py $f ; done
test1-bad.c: []
test1-good.c: [CursorKind.UNEXPOSED_EXPR]
test2-bad.c: []
test2-good.c: [CursorKind.INIT_LIST_EXPR]
test3-bad.c: [CursorKind.TYPE_REF]
test3-good.c: [CursorKind.TYPE_REF, CursorKind.INIT_LIST_EXPR]
```

Tested with version 12.0.0 and 13.0.0 of the libclang python bindings on Ubuntu 20.04

## demo.py
```
import sys
from clang.cindex import Index
idx  = Index.create()
tu   = idx.parse(sys.argv[1])
crsr = [c for c in tu.cursor.get_children() if c.spelling == "my_global"][0]
print("%s: %s" % (sys.argv[1], [child.kind for child in crsr.get_children()]))
```

## test1-bad.c

```
#include <stddef.h>
char *my_global = NULL;
```

Output is the empty list but should be `[CursorKind.UNEXPOSED_EXPR]`

## test1-good.c

```
#include <stddef.h>
char *my_global = 0;
```

## test2-bad.c

```
#include <stddef.h>
char *my_global[] = {"hello", NULL};
```

Output is the empty list but should be `[CursorKind.INIT_LIST_EXPR]`

## test2-good.c

```
#include <stddef.h>
char *my_global[] = {"hello", 0};
```

## test3-bad.c

```
#include <stddef.h>
struct test {char *a; int b;};
struct test my_global[] = {{"hello", 7}, {NULL, 3}};
```

Output is `[CursorKind.TYPE_REF]` but should be `[CursorKind.TYPE_REF, CursorKind.INIT_LIST_EXPR]`

## test3-good.c

```
#include <stddef.h>
struct test {char *a; int b;};
struct test my_global[] = {{"hello", 7}, {0, 3}};
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy9Vttu2zgQ_Rr5ZVBBpmzHfvBDfAkQbDYt2qTYfTIoiZLY0qJAUk69X78zlJQoNydAswvI1mVmOGfOXMhEZ8flTSlAySRVvCqgPrpSV5DIKpNVYYEbAamurLROVE4dodIOjHCNqVAODm1lJZ3kSv4jDKSlVBmkjbHaQI6_YBZ9P_-622zXV_jYSSzIHDjJrm-v_HdpoTbCogsI2JzXNfoldwFbAK-Od6Uw5OipvxBuSjSVVaqaTNgHEWHjcOCqEeD0wFPA1vSBVxiZ4Ue4k64E7kAJbh3oSgxRCSX2CINsMBQyA-tMk2L0orMcqudSYPCEv8rACrG33qaukTaMwKO3wlNaCeQzA27hTiiFUYYQRJsgOm__by0F4OHO8TpomQXsHNXww8LzVaE9z0DnQwCZRg4oQbXRWZNi6J4daxtBMVQYhFdp-uUj_IVDx1QLuVZK33UamdjrsD7S6j4xWulC4hKUW_LEneOY9KrwxKJ1gbQ0CdS8EPBTiNp2YHxGKhDGoKVn4xKc8QmWSjXIK3e4rk8wAYbkCFmzr_sq85WFRUEhe9b3x12hdMIVYTtwI3miBGYQmT8IwxVYvq_xyxrzooR9TDBR217tK5v4iHKqMWQ6TIN4hVz17RAG7KJjAsUTJN2LK9GaI3A3_pTwjOzOIZiugulmKCq0fpCtfQ_8gR0W3l5v__ry-dt2s8P710dG7PX12KvrXV5f3uyuLr_dPF8vfrTewObm7y_b3dftxRPt11zcq2O-3_b8lOe2yNri9w2EqbISGR6zMAojoM4Zx_4R8-xOTSZ8vk2ayjXAUH3yKLssxgv62n0JidzX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