<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">I’ve been experimenting with SEH handling in LLVM, and it seems like the unwind funclets generated by LLVM are much larger than those generated by Microsoft’s CL compiler.<div class=""><br class=""></div><div class="">I used the following code as a test:</div><div class=""><br class=""></div><div class="">void test() {</div><div class=""> MyClass x;</div><div class=""> externalFunction();</div>}<div class=""><br class=""></div><div class="">Compiling with CL, the unwind funclet that destroys ‘x’ is just two lines of asm:</div><div class=""><br class=""></div><div class=""><font color="#000000" face="Menlo" class=""><span style="caret-color: rgb(0, 0, 0); font-size: 11px;" class="">lea</span><span style="font-size: 11px;" class=""> rcx, QWORD PTR x$[rdx]</span></font></div><div class=""><font color="#000000" face="Menlo" class=""><span style="font-size: 11px;" class="">jmp </span></font><span style="color: rgb(0, 0, 0); font-family: Menlo; font-size: 11px;" class="">??1MyClass@@QEAA@XZ</span></div><div class=""><span style="color: rgb(0, 0, 0); font-family: Menlo; font-size: 11px;" class=""><br class=""></span></div><div class=""><font color="#000000" face="Menlo" class=""><span style="font-size: 11px;" class="">However when compiling with clang-cl, it seems like it sets up an entire function frame</span><span style="font-size: 11px;" class=""> just for the destructor call:</span></font></div><div class=""><font color="#000000" face="Menlo" class=""><span style="font-size: 11px;" class=""><br class=""></span></font></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">mov qword ptr [rsp + 16], rdx</span></div></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">push rbp</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">.seh_pushreg 5</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">sub rsp, 32</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">.seh_stackalloc 32</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Lea rbp, [rdx + 48]</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">.seh_endprologue</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Lea rcx, [rbp - 16]</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">call </span>"??1MyClass@@QEAA@XZ”</div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class="">nop</div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">add rsp, 32</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">pop rbp</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">ret</span></div></div><div class=""><span style="color: rgb(0, 0, 0); font-family: Menlo; font-size: 11px;" class=""><br class=""></span></div><div class=""><font color="#000000" face="Menlo" class=""><span style="font-size: 11px;" class="">Both were compiled with </span><span style="caret-color: rgb(0, 0, 0); font-size: 11px;" class="">“/c /O2 /MD /EHsc”</span></font></div><div class=""><font color="#000000" face="Menlo" class=""><span style="font-size: 11px;" class=""><br class=""></span></font></div><div class=""><font color="#000000" face="Menlo" class=""><span style="font-size: 11px;" class="">Is LLVM missing a major optimisation here?</span></font></div></body></html>