<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/54900>54900</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
SEH for Windows aarch64: Invalid RegF count for packed unwind data
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
egelke
</td>
</tr>
</table>
<pre>
There is an issue when clang generates a packed unwind data including Float Registers, when you provide a even number of RegF the generated packed unwind data has an odd number (2 -> 1, 4 -> 3, ...).
For example:
```asm
.global _start
_start:
.seh_proc _start
stp x19,x20,[sp,#-0x30]!
.seh_save_regp_x x19, 0x30
stp d8,d9,[sp,#0x10]
.seh_save_fregp d8, 0x10
stp d10,d11,[sp,#0x20]
.seh_save_fregp d10, 0x20
stp fp,lr,[sp,#-0x10]!
.seh_save_fplr_x 0x10
mov fp,sp
.seh_set_fp
.seh_endprologue
//return value
mov w0, wzr
.seh_startepilogue
ldp fp,lr,[sp],#0x10
.seh_save_fplr_x 0x10
ldp d10,d11,[sp,#0x20]
.seh_save_fregp d10, 0x20
ldp d8,d9,[sp,#0x10]
.seh_save_fregp d8, 0x10
ldp x19,x20,[sp],#0x30
.seh_save_regp_x x19, 0x30
.seh_endepilogue
ret
.seh_endfunclet
.seh_endproc
```
Generates the following pdata (`dumpbin /UNWINDINFO bin\Program.exe`):
```
Start=40001000 Flag=1 FuncLen=2C RegF=3 RegI=2 H=0 CR=3 FrameSize=0x40
[RawPdata=00001000 0262602D]
+0000 stp x19,x20,[sp,#-0x30]!; Actual=stp x19,x20,[sp,#-0x30]!
+0004 stp d8,d9,[sp,#0x10] ; Actual=stp d8,d9,[sp,#0x10]
+0008 str d10,[sp,#0x20] ; Actual=stp d10,d11,[sp,#0x20]
**** Expected opcode FD0013EA
+000C stp fp,lr,[sp,#-0x10]! ; Actual=stp fp,lr,[sp,#-0x10]!
+0010 mov fp,sp ; Actual=mov fp,sp
Epilog #1 unwind: (Offset=18)
+0018 ldp fp,lr,[sp],#0x10 ; Actual=ldp fp,lr,[sp],#0x10
+001C ldr d10,[sp,#0x20] ; Actual=ldp d10,d11,[sp,#0x20]
**** Expected opcode FD4013EA
+0020 ldp d8,d9,[sp,#0x10] ; Actual=ldp d8,d9,[sp,#0x10]
+0024 ldp x19,x20,[sp],#0x30 ; Actual=ldp x19,x20,[sp],#0x30
+0028 ret ; Actual=ret
```
Although d8/d9 and d10/d11 are coded exactly the same in asm; the former is saved as pair in the pdata while the later is saved as a singleton.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVt9vozgQ_mvIi1VkDMnCAw9pUm4rnbqr9k77WDl4-HHrYGQgSfevv7EJbUjSNJWKEjCe8XwzjOfzrJR4if8pQAMpG8IrvDcdkG0BFUklr3KSQwWat4BSUvP0NwjSVduyEkTwlpOySmUnSlRMpOIteYS8bFrQjcMWvZkX1ZFaq00pAE3ABqeqbr0CTVRm1BPSFvAKI86BFNz6poQYljosZOTG8e-IZ4CCfuybseu6Dotchy4dOu_vidIEdnxdS3D8-aHEmdH-x5t1P0PwcnOpVlyS56bluu3n9-NhuVVroHjG0NKRopE0bU3IzovQnx2jeHemt01tnsy_oTufOtOlw7wjUw3fwLOGvH7e7RcTqzs2K0IUiGhslO48a_OMwcxY7FcRq3ZkzjP-Cc87Nsg-MGjXEas3tpgZE1KfRO1diDqrpcaox_6t1WZvDa0cLYIW1xxNQiUwG1LlHRzm2MgdluBPQ9vpimy4HDQGmK0NZvtHHy_s0Ux2oS4PTBuZFGeiNSG-ZuTaSK2lL81Eb_HLtoo1d7qh34L1zwZ7aTMPKTv9rpimU7WsQ6Y5JzAFeFTMh0n865W_DM1kSkq1NXRVW2ZBHkF90a3rVVmZXfLvw6_7h-X9Q_KD4IwzXfzUKtd87cIOjGUWvTHIGA5deuopYhlQSj38EyRFnuOEhyP0_2-o8AW_hOU9HPp2dG8mCfmOD1yyeOwFCaLCU_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