The given program compiled with ldc 1.7.0 and the switches -O3 -release -betterC
class Foo { bool status; this(bool status) { this.status = status; } } void main() { auto f = new Foo(true); import core.stdc.stdio; printf("%d", f.status); }
produces this optimized code:
_D7example3Foo6__ctorMFbZCQyQs: mov byte ptr [rdi + 16], sil mov rax, rdi ret _Dmain: push rax lea rdi, [rip + .L.str.1] mov esi, 1 xor eax, eax call printf@PLT xor eax, eax pop rcx ret
Change auto f = new Foo(true);
to scope f = new Foo(true);
and the following less optimal asm is produced:
_D7example3Foo6__ctorMFbZCQyQs: mov byte ptr [rdi + 16], sil mov rax, rdi ret _Dmain: sub rsp, 24 mov rax, qword ptr [rip + example.Foo.__vtbl@GOTPCREL] mov qword ptr [rsp], rax mov qword ptr [rsp + 8], 0 mov byte ptr [rsp + 16], 1 lea rdi, [rip + .L.str.1] mov esi, 1 xor eax, eax call printf@PLT mov rdi, rsp call _d_callfinalizer@PLT xor eax, eax add rsp, 24 ret
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4