Getting action on your favorite D issues

Patrick Schluter Patrick.Schluter at bbox.fr
Sat Jun 6 15:36:07 UTC 2020


On Saturday, 6 June 2020 at 14:34:11 UTC, Avrina wrote:
> On Saturday, 6 June 2020 at 10:09:07 UTC, Patrick Schluter 
> wrote:
>> On Friday, 5 June 2020 at 23:53:28 UTC, H. S. Teoh wrote:
>>> Output:
>>> -----------------
>>> dead
>>> -----------------
>>>
>>> Truly, DMD's backend is in the bright future of strange and 
>>> wonderful quantum effects, whereas LDC is clearly still stuck 
>>> in the antiquated classical past. ;-)
>>>
>> Sorry, but undefined behaviour is undefined behaviour. The dmd 
>> code generator is not at fault here.
>
> With statements like this I always feel like people don't 
> understand what "undefined behavior" means.
>
> All the void initializer does is not initialize the memory of 
> the bool. DMD is testing more than a single bit for a type that 
> is only a single bit, it flip flops between testing a byte and 
> testing a bit. That is most definitely a bug in the DMD backend.

Then it is also a bug in llvm and gcc as they generate the code 
under exactly the same assumption that a bool is 1 or 0 (and that 
in C, C++ and D).
Only in contexts where there is int promotion is all the word 
checked.

This has nothing to do with the D frontend, #pure or whatnot. 
It's a pure backend code generation assumption.
If the frontend violates that assumption, it is an issue of the 
frontend.

>
> Just to bring up an old debate, this has been argued to not be 
> a bug and is defined behavior and *will not* be changed.
>
>   void foo(bool);
>   void foo(byte);
>
>   foo(0); // calls bool
>   foo(1); // calls bool
>   foo(2); // calls byte

This has nothing to do with the issue at hand.
This it's a technical choice. It might be surprising, it is very 
likely a wrong choice, but it is not violation of the assumption 
of the backend (even if it a violation of the programmer).




More information about the Digitalmars-d mailing list