https://issues.dlang.org/show_bug.cgi?id=20148
Patrick Schluter <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |[email protected]. | |eu --- Comment #4 from Patrick Schluter <[email protected]> --- (In reply to hsteoh from comment #2) > There's more to it than a hole in @safe. Look at the disassembly below, > there seems to be a codegen bug as well: > > ------------------- > 000000000003f698 <_Dmain>: > 3f698: 55 push %rbp > 3f699: 48 8b ec mov %rsp,%rbp > 3f69c: 48 83 ec 10 sub $0x10,%rsp > 3f6a0: 40 8a 7d f8 mov -0x8(%rbp),%dil The bug is here and only in dmd! gdb and ldc use movzx to load the EDI register no mov. When b is initialized the error doesn't manifest as it reuses the EAX register to load EDI that it had used to zero the byte. This said. The example doesn't compile with option -O . It returns then <source>(4): Error: variable b used before set > > Even though technically this codegen works if b is either 0 or 1, it seems > inconsistent at best (why compare the entire 32-bit value to 0 when checking > for false, but only the lower byte when checking for true?), and in this > case outright wrong when b is uninitialized and therefore can have any > random garbage value other than 0 or 1. This is C integer promotion rule. bool being really just an integral type with 2 values instead of being a real special thing (see Java for the drawbacks of that). --
