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

    <tr>
        <th>Summary</th>
        <td>
            -Wreturn-stack-address should handle clang::musttail calls
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          efriedma-quic
      </td>
    </tr>
</table>

<pre>
    As noted at https://github.com/llvm/llvm-project/issues/56435#issuecomment-1192823619 and https://github.com/llvm/llvm-project/issues/56435#issuecomment-1179143671, there's a potential trap with musttail calls: all local variables are freed by the call.  So if you pass a pointer to a local variable, and try to use it, it's a use-after-free.  We should warn if someone writes something like the following:

```
int bar(int* x);
int foo(int*) {
    int local = 11;
    [[clang::musttail]] return bar(&local);
}
```

This is very similar to the existing -Wreturn-stack-address, so it probably makes sense to put it into the existing warning group.

(While we're looking at this, it might also be nice to update the documentation for clang::musttail.)

CC @foonathan @haberman 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytU8ty2zAM_BrqgpHHol7WQQcnnv5AO5MzJUEWa4pU-Yjjvy8oxUna8a3VcESCILGLBdiZ4dYeHWjjcQDhYfJ-cSw_Mv6Nxln6KXS73sxkKPV6n9LFmp_YezKlcwEdLcqqyEvG83WDbsyofZplDT_wvMoaEHr4_9HrJivyqs4YfwY_oUXGawcCFspHeykUeCsWuBISzMF5L6SCXigVWQDNoAyZ8CqsFJ1CumsRRoukRneLIdfTO4DvBuQINxNgEW6DkNqjBW_I-DNKZBPT9fYW3cEhSB8343_lR1upGOl6GrEo_AuCm0xQA1yF1RHKmRmNRrha6YlXNP0k9RmUvODKbDRKmSttRUX3J7a__6v9-1hNogmdsIwfaMX4Ed4Yb1j-9Okdjfnwkg9Y_e4E-uKBLT2WnyDLPm5GJyufaPRKbCTy411kVp5ogEUfKJ0NnvFqDfQVntWnh6S3_49JOqDxiqSkk7NUYhU8Zo9v0vmoR_qyoaTOi_6SimGw6FyU21HNPFA3dVSVG8ziEoVETfWgIEvw0U35_RUwViDOZ2vCsvtDWX54maSiosRGo05RxlziUXo5VBy31RhmeZ48dRfhdwha9iteWAbht8oNpg-xg4WXRpP8Fh5IuIs6fQF_fgZW7KlWWvhJ6GhMokM70zoZ2nxo8kYkXnqF7WNN7i1GtwdK4gHm9jaSYFX7L2-1qqtkartyzPJ9jTnvhChEkR-KvuiyohvGkWPTJIroK9fGJuJc4xXWELSm1klky_ec72vOsybjZbXreJPlh6HIGlEMZVlR_jhHnSKPnbHnxLYrpS6cHTkVldN9OunVyrNGXOEovgh-MrbF0UocZpH-CrJPVgLtmsBvLJOlBw">