<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61721>61721</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
CFI directive is ignored by AsmPrint and leads to an assertation fail in bolt
</td>
</tr>
<tr>
<th>Labels</th>
<td>
BOLT,
llvm
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
linsinan1995
</td>
</tr>
</table>
<pre>
After this [patch](https://reviews.llvm.org/D32246), asmprinter skips emitting CFI instructions if it is at the end of the function. However, this might lead to unmatched cfi_restore_state/cfi_remember_state pair and this triggers an assertation failure in bolt.
```
assert(Depth == 0 && "unbalanced RememberState/RestoreState stack");
```
a test case in aarch64: https://reviews.llvm.org/F26307823
llc unmatched.ll -mtriple=aarch64-none-eabi -o test.s
then you can see there are 7 cfi_remember_state and 6 cfi_restore_state.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEU1HLrDYQ_TXxZViJyarrgw-7n0gLhZbbvl-ijjq9MUoy7uX79yW67dfSDy6IOiE5c3LOGRMCTQ6xFvlD5E1idp5XX1tygZxxWVXlSbcO7_V9ZPTAMwUQ-WMz3M8ib4S6zcxbEPouVCtU6_FJ-D2k1j6XdPWTUG2jlboWQlVCvYEJy-bJRazwjbYAuBAzuQne2p-BXGC_90yrC0AjEAMFMAw8I6AbYB2P33F3x6YUflq_4xN9hD7JLTTNDBbNALzC7pbIFAfoR_rqMfDq8WtgwyhUe64tuHToz0XYDHkwbjjB2NM0oQ9gHJgQ0LOJbWE0ZHePQA661XIqZCPk_fUu5Os5yvOYULcGN55B6EboBiQIVQhVgFBqd52xxvU4wJcXmd9fBL-chI8SApv-m1AqKqkfnzZ7tQTGwNCbcDA0xvdzcRX6Dj_0qlWFluVN6RPJ2v5DwtRauCzsabModPOCvbjV4QVNR3BZj8Zp-DcZntHB-7pDbxwExOifRzAeoYRPDIjaF_936yVxMtR6qHRlEqyzoqwqmUmZJ3NdyiLv8iuOaMpOZ1WR67G7XfubLMY8L24J1UoqLbUqZRnPpNdiRN2bvEOZDbLKxFXiYsj-I0dCIexYF1mpssSaDm04pkSpx6-__HEY8SaUittjkTeJr2Nx6fYpiKu0FPhD3ISJLdYx5QN57JmeGMNNk1s9DtC9wz0sv8XZODSICQ4xwp9E7-_cJbu39X89nYjnvUv7dRGqPakdn8vm1z-xZ6Ha41pBqPa42V8BAAD__4dzS24">