enforce (i > 0) for i = int.min does not throw

Steven Schveighoffer schveiguy at yahoo.com
Sun Jan 28 19:17:49 UTC 2018


On 1/27/18 9:50 AM, ag0aep6g wrote:

> Wow, that looks really bad.
> 
> Apparently, dmd implements `i < 0` as a `i >> 31`. I.e., it shifts the 
> bits to the right so far that only the sign bit is left. This is ok.
> 
> But it implements `i > 0` as `(-i) >> 31`. That would be correct if 
> negation would always flip the sign bit. But it doesn't for `int.min`. 
> `-int.min` is `int.min` again.
> 
> So dmd emits wrong code for `i > 0`. O_O
> 
> I've filed an issue:
> https://issues.dlang.org/show_bug.cgi?id=18315

This is insane. i > 0 is used in so many places. The only saving grace 
appears to be that int.min is just so uncommonly seen in the wild.

I tested all the way back to 2.040, still has the same behavior.

-Steve


More information about the Digitalmars-d-learn mailing list