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

    <tr>
        <th>Summary</th>
        <td>
            libunwind::Registers_mips_o32::jumpto returns to the wrong address
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          Jade-Marker
      </td>
    </tr>
</table>

<pre>
    In libunwind::Registers_mips_o32::jumpto, there is the following code
```
  lw    $30, (4 * 30)($4)
  // load new pc into ra
  lw    $31, (4 * 32)($4)
  // jump to ra, load a0 in the delay slot
 jr    $31
```

However, this does not work as intended! On mips, offset loads have a delay. So instead of returning to the new value of $ra, the program returns to the old value. This means that it instead returns to the end of UnwindCursor::jumpto, where both $sp and $ra are immediately overwritten.

There is a simple fix to this though. As the delay is only 1 cycle, swapping the order of the previous instruction ensures that $ra has the correct value on jump

```
  // load new pc into ra
  lw    $31, (4 * 32)($4)
  lw    $30, (4 * 30)($4)
  // jump to ra, load a0 in the delay slot
  jr    $31
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVNGOqzYQ_RrzMlpkDGThgYd0q6itVFVqb5-vHDyA9xoP8pjQ_H1lyPZ2V7oPt6oUKSTjM3POmYM1sx09YifqH0T9Y6bXOFHoftEGn37V4QuG7Erm3v3swdnr6jfrjSjPojz_jqPliIE_z3bhz1Sq4__XdV4iCfUCccKAYDk9wEDO0Wb9CD0ZFPIsTvLxkWcAtwEACFWVMkGFaioQ6gzpZytUI1RVpad0VqiLUBdwpA143GDpwfpIEPSHVsX7VuqbrRJnODqol6OxlmD9ztyg03dgRzFBXsPX7u9FCHn-iTa8YTjEWwZDyOApwkbhC2hOPNEbNEIV8JuH5Fw6TMPAGPfBDJO-IehjbA5_EFjPEbUBGiBgXINPLkbaySX9N-1WTFWhqkNBqiyBxqDnB4TfAOTMAcjhU6I4o07FSUew8Z9RH0Do9-l_7ut_WQNT-LjsbV_2leKUaPAC2puDEOiUgnlGY3VEdwe6YdiCjRF9fvj26S0pGtjOi0MY7F_H8D0-tI5TDmf-1z4sA3l3hwL6e-8wUeBNL8vuTdIZDIZE-vACb5ZW3vWFtY-WPKDnNeBD-8F00seInkLAPr456_eAHFTfx_Z_jOJ_eAO-I7bfym1mutK0Zasz7IrnumrKtimabOraSg3VMOihPBVtXfeyl7quW1WgbE7PSme2U1LVsilkUZeyaPKT1I00xfNzU52KskVRSZy1dblztzmnMGaWecWuqFWrVOb0FR3v945Sybu9KpRK11DoEujpuo4sKuksR_7aJtrosPuu6-hjoLdAfgRtTEDmbA2um2JcOEF2a0cbp_Wa9zQLdUmDH19PS6BX7KNQl50uC3V56Ll16u8AAAD___PCofk">