Bug 4083 – Exception-related code from nothrow destructor
Status
RESOLVED
Resolution
WORKSFORME
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-04-12T04:29:17Z
Last change time
2018-05-17T12:21:33Z
Keywords
performance
Assigned to
No Owner
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2010-04-12T04:29:17Z
This can be related to bug 4082.
This program works correctly with dmd 2.043, but the resulting asm contains code for the management of exceptions even if the destructor of the struct Foo is nothrow (I am not sure if this situation can be improved):
struct Foo {
nothrow ~this() {}
}
void main() {
Foo f;
goto NEXT;
NEXT:;
}
__Dmain
L0: push EBP
mov EBP,ESP
mov EDX,FS:__except_list
push 0FFFFFFFFh
push offset __Dmain[061h]
push EDX
mov FS:__except_list,ESP
sub ESP,8
push EAX
push EBX
push ESI
push EDI
mov dword ptr -4[EBP],0
mov dword ptr -4[EBP],0FFFFFFFFh
lea ECX,-0Ch[EBP]
push 0FFFFFFFFh
push ECX
push offset FLAT:_DATA
call near ptr __d_local_unwind2
add ESP,0Ch
push offset __Dmain[04Eh]
mov dword ptr -4[EBP],0FFFFFFFFh
ret
mov ECX,-0Ch[EBP]
xor EAX,EAX
mov FS:__except_list,ECX
pop EDI
pop ESI
pop EBX
mov ESP,EBP
pop EBP
ret
mov EAX,offset FLAT:_DATA
jmp near ptr __d_framehandler
Comment #1 by dmitry.olsh — 2018-05-17T12:21:33Z
Now on DMD 2.079 nothrow is optimized well, so it was fixed in the meantime:
000000000000000 <_Dmain>:
0: 55 push %rbp
1: 48 8b ec mov %rsp,%rbp
4: 48 83 ec 10 sub $0x10,%rsp
8: 48 8d 45 f8 lea -0x8(%rbp),%rax
c: c6 00 00 movb $0x0,(%rax)
f: b9 03 00 00 00 mov $0x3,%ecx
14: 89 4d fc mov %ecx,-0x4(%rbp)
17: 48 89 c7 mov %rax,%rdi
1a: e8 00 00 00 00 callq 1f <_Dmain+0x1f>
1f: 83 7d fc 03 cmpl $0x3,-0x4(%rbp)
23: 74 02 je 27 <_Dmain+0x27>
25: c9 leaveq
26: c3 retq
27: 31 c0 xor %eax,%eax
29: c9 leaveq
2a: c3 retq