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

    <tr>
        <th>Summary</th>
        <td>
            __cxa_demangle terminates the program on failure to allocate
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            libc++abi
      </td>
    </tr>

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

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

<pre>
    As explained in https://reviews.llvm.org/D155598, we currently terminate the program after failing to (re)allocate inside the Itanium demangler. This happens when we fail to grow the `OutputBuffer` inside `ItaniumDemangle.h`.

Instead, we should properly handle failure-to-allocate inside `ItaniumDemangle.h` and propagate something like an error code or a `std::expected` to the caller of all functions in the demangler that can allocate. Then, we could make sure that `__cxa_demangle` returns `nullptr` when it fails to demangle the input due to any error, as it is supposed to.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0U0GPszgM_TXhYhWlAUp74NBuVWlOe9n7yCUGshMSlDjT6b9fhbYzmpW-Cxxsv-f3nIcxmtERdaI5ieZcYOLJh85q452j4ur1vTtGoK_FonGkwTiYmJcoqqNQF6EugT4N3WJp7edc-jAKdTlvm6Y57IX6C24EfQqBHNs7MIXZOGQCngiW4MeAM-DAFGBAY40bgT0ItQ8k1AGt9X3uNi4a_Rh6Y3QmzaBpRjdaCiX8M5kIEy4LuQi3iVwmzXAZawz-tg6Knfw78ZL4lIaBgtjJF6zYySfq-QlaTmInSyHPQh4f3zcXmVA_FcXJJ6uzgIWCvcOETtsHZwq0Yb_5_-p_4AB0Dxgcc3P0M_GUXbDmgwAdUAg-QO81gQ-AGSeyzt5XR_paqGfSGYf9KrJHaymAHwCthSG5no13MR8tl79NA56QoUcHr0WzjeReF1vlzfhBEFOgR7fYyff3_gvfXyiZNxCn4GIuumTtwqux6xEMr4bEvNtrZN3CuCUx6ES5gu7-EJmpMeYpEyGmZfGRNLAvC91V-lAdsKBuuzts66ppZVtM3aGVWvVVXbd1pdpeYbNvdNNK1VC7H_ayMJ2SqpJ72W4P20a25VDVfVPv261q2qtuSdSSZjT2--0WJsZE3a5uZFNYvJKNazCUsubaC3US6oRXI5TKWQldnttc0xhFLa2J_JOCgg1b6n479hOA-CsB3r3ezmrJ8yRFCrb7nbXR8JSuZe9noS6Z6vnbLMH_Sz0LdVkVRKEuq4j_AgAA__-Lnk7D">