digitalmars.D.bugs - [Issue 17347] New: DMD generates different (and wrong) output in
- via Digitalmars-d-bugs (81/81) Apr 24 2017 https://issues.dlang.org/show_bug.cgi?id=17347
https://issues.dlang.org/show_bug.cgi?id=17347 Issue ID: 17347 Summary: DMD generates different (and wrong) output in -release mode Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Severity: enhancement Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: alexander.breckel gmail.com The following snippet correctly prints "0" when compiled with dmd (no -release) or ldc. However, adding -release prints a weird value. The value is slightly different for each run, but stays in the same number region. DMD64 D Compiler v2.074.0 (ArchLinux) $ dmd -release app.d && ./app 140734704773424 I was not able to further reduce the code, as changing seemingly unimportant things, like removing the "number" field from Wrapper, "fixes" the issue: import std.stdio; void main() { writeln(f(Wrapper(ABCD.B, 1)).length); } enum ABCD { A, B, C, D } struct Wrapper { ABCD abcd; uint number; } bool[] f(Wrapper x) { final switch(x.abcd) { case ABCD.A: case ABCD.B: case ABCD.C: case ABCD.D: return []; } } Here's the relevant output of objdump -D, just in case it helps: 000000000043abc8 <_Dmain>: 43abc8: 55 push %rbp 43abc9: 48 8b ec mov %rsp,%rbp 43abcc: 48 83 ec 10 sub $0x10,%rsp 43abd0: c7 45 f8 01 00 00 00 movl $0x1,-0x8(%rbp) 43abd7: c7 45 fc 01 00 00 00 movl $0x1,-0x4(%rbp) 43abde: 48 8b 7d f8 mov -0x8(%rbp),%rdi 43abe2: e8 0d 00 00 00 callq 43abf4 <_D3app1fFS3app7WrapperZAb> 43abe7: 48 89 c7 mov %rax,%rdi 43abea: e8 41 00 00 00 callq 43ac30 <_D3std5stdio14__T7writelnTmZ7writelnFNfmZv> 43abef: 31 c0 xor %eax,%eax 43abf1: c9 leaveq 43abf2: c3 retq ... 000000000043abf4 <_D3app1fFS3app7WrapperZAb>: 43abf4: 55 push %rbp 43abf5: 48 8b ec mov %rsp,%rbp 43abf8: 48 83 ec 10 sub $0x10,%rsp 43abfc: 48 89 7d f8 mov %rdi,-0x8(%rbp) 43ac00: 48 83 ff 03 cmp $0x3,%rdi 43ac04: 77 26 ja 43ac2c <_D3app1fFS3app7WrapperZAb+0x38> <_IO_stdin_used+0x10> 43ac0d: 48 63 0c b8 movslq (%rax,%rdi,4),%rcx 43ac11: 48 8d 04 01 lea (%rcx,%rax,1),%rax 43ac15: ff e0 jmpq *%rax 43ac17: 31 f6 xor %esi,%esi 67ec40 <_D11TypeInfo_Ab6__initZ> 43ac20: e8 0f 22 00 00 callq 43ce34 <_d_arrayliteralTX> 43ac25: 48 89 c2 mov %rax,%rdx 43ac28: 31 c0 xor %eax,%eax 43ac2a: c9 leaveq 43ac2b: c3 retq 43ac2c: c9 leaveq 43ac2d: c3 retq ... --
Apr 24 2017