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

    <tr>
        <th>Summary</th>
        <td>
            RISC-V va_end generates what seems to be unnecessary code
        </td>
    </tr>

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

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

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

<pre>
    RISC-V ABI docs say that `va_end` is a no-op:

> The va_copy macro is a single pointer copy and the va_end macro performs no operation.

https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-cc.adoc#va_list-va_start-and-va_arg

But LLVM seems to generate the following code:

```
void nop(va_list l) { }
void call_va_end(va_list l) { va_end(l); }

nop(void*):
 ret

call_va_end(void*):
        addi    sp, sp, -16
        sd a0, 8(sp)
        addi    sp, sp, 16
 ret
```

https://godbolt.org/z/P73hcfvoh

I don't know RISC-V at all, but at a glance that seems to be doing nothing useful? It seems to be allocating 16 bytes on the stack, saving `a0`, and then deallocating those bytes.

GCC does not do this: https://godbolt.org/z/Y1d833vrE
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVF-L4zYQ_zTKy-Bgy4mdPPhhN3suC1cobTnoUxhLE1s9RWMs2Uv66YscJ5ddlrsQJMbzm_mN5h96b1pHVInts9i-rHAMHQ-VxsnohtyqYX2p_nz965B8g6fnV9CsPHi8QOgwgCjSCY_ktChSMB4QHCfci_xJpC8ivZ35F_i7I5jwqLi_wBnVwFe4N661BD0bF2iAWY1OQ7jCyekF3dNw4uHswTFwTwMGw279yNKF0PvILGsh69aEbmzWis9C1oPxakocu8R4vMtkT0nvsTGJZiVk3VhuhKzP6AMNd5RSa5z1-YRHa3xIJjz6gENI0Oko4NA-xvE8Bvj69dvv4InOHgJDSy4GTPOrTmwtvxnXgmJNHzNVpMt_Fic2Ghz3Qu4WcrBC7kGUzyDKlweQQmuPSyk-Ad818YvIH6yv58LBRgv5NEMWBQwUHoEfeD4xWH6otYm374U8LGeSFe9BXgOmUbMTchcx-187ufv4Edn7pH3aDawbtmHNQytk_Z-Q9R9l3qnTxN2jUWxvJ2QZ4LvjN1jaHgOgtZG7GcMsQWvRKbrOwL3MDYHmWFjHoYv36Ok0WpHX8PoehtaywhAxWQHNJZAHdnN7-IDq-_xanKJeFCnOb5OH22A40PTgIXTs6erk3Tz8djiAZooTE0AzhM7EhMCvMvNPpnd5Pg1fVrrK9T7f44qqrMyzYr_dSLnqqmJT6GxTbtU2VaU-ye2-TGW61ajlrqS8WJlKpnKTZdk22-WplOsTNaci18VpK_flXmmxSemMxq6tnc6Re2W8H6nKsmKT7VYWG7L-tpKGKqKSZmy92KSxsf0Pu2CCpduCWjbGbd48vH0s0OgcKfIeh8s8f6txsNVPNkfkWa6kH_hfUkHIeg7WC1kv8U6V_D8AAP__Wc-eMA">