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

    <tr>
        <th>Summary</th>
        <td>
            Clang AST dump does not provide all information
        </td>
    </tr>

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

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

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

<pre>
    Hello, I started using clang's `-ast-dump` feature and I found that the AST it produces does not contain all original information.

It is easier to see it with the following example:

```C
int func1();

typedef double (*callback)(int param1);
```

The `test.c` above contains 1 function and one callback declaration (a typedef for a function pointer type). Now let's produce the JSON AST for the example above with `clang -Xclang -ast-dump=json test.c`. We get the AST and the the bits relevant to our example are

The `func1` AST:
```JSON
{
      "id": "0x598de3e85e50",
      "kind": "FunctionDecl",
      "loc": {
        "offset": 4,
        "file": "llvm.c",
 "line": 1,
        "col": 5,
        "tokLen": 5
      },
 "range": {
        "begin": {
          "offset": 0,
 "col": 1,
          "tokLen": 3
        },
        "end": {
          "offset": 10,
          "col": 11,
 "tokLen": 1
        }
      },
      "name": "func1",
 "mangledName": "func1",
      "type": {
        "qualType": "int ()"
      }
    },
```
In this example there is no node for the return type (`int`). We have a full function signature that includes the function parameters. But it makes sense to have a node for the return type itself to avoid parsing types at the client side. Note that callback declaration below **does contain** a node for the return type.

Now let's look at the second example for callback:

```JSON
    {
 "id": "0x598de3e860b8",
      "kind": "TypedefDecl",
 "loc": {
        "offset": 31,
        "line": 3,
 "col": 18,
        "tokLen": 8
      },
      "range": {
 "begin": {
          "offset": 14,
          "col": 1,
 "tokLen": 7
        },
        "end": {
 "offset": 51,
          "col": 38,
          "tokLen": 1
 }
      },
      "name": "callback",
      "type": {
 "qualType": "double (*)(int)"
      },
      "inner": [
 {
          "id": "0x598de3e86050",
          "kind": "PointerType",
          "type": {
            "qualType": "double (*)(int)"
          },
          "inner": [
 {
              "id": "0x598de3e85ff0",
              "kind": "ParenType",
              "type": {
                "qualType": "double (int)"
              },
              "inner": [
 {
                  "id": "0x598de3e85fc0",
 "kind": "FunctionProtoType",
                  "type": {
 "qualType": "double (int)"
                  },
 "cc": "cdecl",
                  "inner": [
 {
                      "id": "0x598de3e270e0",
 "kind": "BuiltinType",
                      "type": {
                        "qualType": "double"
 }
                    },
                    {
 "id": "0x598de3e26fc0",
                      "kind": "BuiltinType",
                      "type": {
 "qualType": "int"
                      }
 }
                  ]
                }
              ]
 }
          ]
        }
```

In this example the function parameters (e.g. node `0x598de3e26fc0`) **do not contain** parameter names. Note that function declaration does contain such information.

```
$ clang --version
clang version 17.0.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0WN2O4jgTfRpzY4EchwS44ILuFvr602p2pGlp9m5l4krwtLFZ26F73n5l5xdIoHtGi0ZDY5erjk_Fpypm1opCAaxR8oCSpwkr3V6bNVPMaTnZaf5z_T-QUiP6iJ-xdcw44Li0QhU4k0wViC4sRimZMuumvDwcUUpwDsyVBjBTHD_jXJeKY7dnDrs94M23FywcPhrNywws5hosVtrhTCvHhMJMSqyNKIRiEguVa3NgTmg1Q-QJkU31_7PDwmJgVoDBTmML4L2-CbcPUXItpX7zMOGdHY4SULzpr0cpqf49Vr-FcjgvVRYhukR0heKHvrX7eQQOOea63EnAwWaTMSl3LHv15nTpHRyZYYfobHkTpu_tZQ-eMgfWzTLPF9vpEzT7tzgKSPyWA4NaAW5iYQ6ZZCbw4WEw3EDLtcGsW3jUQjlPzc8jILqa4S_6DUtwIV8194Go_3_780vIiXfgB2q-alCBUJSSkGw8_av-brMdP_2wWuF2LzP8HXABXapZyH0VayecxQYknJhyPmu6NF08AwMkVTlJiffVpbBh1YOvhxY14zh8EKWCI0pRvPF_k_dkteQQwzKBhPhx-nhh_ipUb8G25vEJMjloLnXWWJ9HDrM6z63nOhjML1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