ldc -O leads to wrong results
Dude via digitalmars-d-ldc
digitalmars-d-ldc at puremagic.com
Sat Mar 14 00:02:50 PDT 2015
On Tuesday, 10 March 2015 at 05:35:59 UTC, Dan Olson wrote:
> "salsa" <salsa at salsa.com> writes:
>
>> Recently I got stuck with this:
>> compiling following code with ldc -O generates code that
>> doesn't do
>> what I expect it to do. Compiling it without optimizations
>> works
>> fine. Does somebody have any idea what the problem might be? To
>> reproduce the bug just compile and run once with 'ldc *.d' and
>> once
>> with 'ldc -O *.d'...
>>
>> x[ 4] ^= rotl((x[ 0]+x[12]), 7);
> ...
>> final static T rotl(T)(T x, T y) pure nothrow @nogc
>> {
>> return (x << y) | (x >>> -y);
>> }
>
> Hi salsa.
>
> y is 7 so (x >>> -7) yields an unspecified value because shift
> is
> negative (see TDPL 2.3.10 Shift Expression). I think results
> are only
> defined when shifting 0 to nbits-1.
Maybe this should be explicitly said in documentation:
http://dlang.org/expression.html#ShiftExpression
Btw. why this is not compile error on the first place?
More information about the digitalmars-d-ldc
mailing list