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

    <tr>
        <th>Summary</th>
        <td>
            AST print falls into infinite recursion and crashes
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang,
            crash-on-valid
      </td>
    </tr>

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

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

<pre>
    In the following code, the `-ast-print` action falls into infinite recursion:
```C++
struct Class {
  struct obj *(*next)(struct Class *q);
};
```
Git bisect tells us that the crash is introduced by ae7c9443559ac420a6f401b7a24eb2fcea8ba3e8 `[AST] Fix printing tag decl groups in decl contexts` back in 2018.05.15 in [D45465](https://reviews.llvm.org/D45465). Clang-7 was the first version affected by this crash, but still crashes today.

[CompilerExplorer](https://godbolt.org/z/zKe6c6arG)

---

It looks to me that printing the field prints the type of the field; which will print the parameters; which will print the pointer's type, and that somehow ends up erroneously again prettyprinting the `struct Class` there with the full definition; which will try to print the field decl, etc. until it crashes.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8VNuSozYQ_Rrx0gUlZMTlgQd7HG9t5XH3B4RojHZliUjNeJyvTwm8mZlUkip86SOhPpcGFaO5OsSeyROT50ytNPvQR0L1c1Y2G_z46L86oBlh8tb6u3FX0H5EJl42lNU8V5HyJRhHrOagNBnvYFLWRjCOPBg3GWcIIaBeQzTescOR8TPjR1bz_Xph4pSuDY0UVk3wYlWMwJonCvDE_fADmDgy0TJxdPhGTHRMtJ_vEsc_Enx43sya8_v_X0338oshGExETUCYSK8RaFa0ydNBxRnMpiT4cdU4wvAAhY3uquogZad0Jbiqp4qXQ6NEhYOYNKp2UAdskz1Mno7fvjN5hot5g82nZCKpK4yoLVyDX5fUYC-1d4RvFJOXg9I_04LgZVtwWZQyVUyezpWsasnkmYl2JlpiclRcmLgEfDV4j4W1r7fChysTl-dm0RXJHHfNG7iruGdqQiR4xS0VUNOEmnaFNJu4q09JDytBJGPtDmEE8qN6FE9D9295evG3xVgMv70t1gcM_0bw6sfBW3py-zN9fsda1yp8SYF9ODDP84_lVwLr_c_UGm64R_Tu5iYG7bhDuzp6LAh-el9khxPcZ6NnuCct29ZtdVFB3ZAwxP_e4o0jDEw0cTs42aLcuPOI_oazvwO6McK6AIbgHfo12geoqzIOloBEj098Wc0_zmwKnGYMCHdD8056tRZG3B6f7bH5xI3CI3nxTnE3IE1RIoekC1gdGQuGfuVWZGN_GLtDpzLsy7prpGzrTmZz3-LU6Losay2mYRCy7LjiTaOxHJWoETPTCy4OJS-bsuaVlEXbta3kreCaazlNmlUcb8rYv2cvMzGu2NfdQfLMqgFt3F40Qug0h0wIJl5Slbjl3uWvypoxwfKchT4dkw_rNbKKWxPpfagzMmSxP377_lT_v2-bLaan_mwNtv_HQBqa16HQ_sbEJXV4_uRL8D9QExOXTUdk4rJJ-SsAAP__qcOuzw">