CTFE difference between dmd and ldc2

Joseph Rushton Wakeling via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Dec 27 09:50:15 PST 2016


Hello all,

I've recently been working on a port of the mir.random Mersenne 
Twister implementation to Phobos, and I've run into a bit of 
weirdness with CTFE.

Specifically, I use some CTFE functionality to generate a default 
starting state for the generator:
https://github.com/WebDrake/mersenne-twister-range/blob/dda0bb006ee4633ae4fa227f9bad1453ba0e9885/src/mersenne_twister_range.d#L126
https://github.com/WebDrake/mersenne-twister-range/blob/dda0bb006ee4633ae4fa227f9bad1453ba0e9885/src/mersenne_twister_range.d#L166

However, it turns out that while this works while compiling with 
the latest ldc2 beta (v1.1.0-beta6, which uses the dmd 2.071.2 
frontend), it doesn't when compiled with the latest dmd master or 
with dmd 2.072.1 (as installed from the deb package downloaded 
from dlang.org).

Specifically, if we look at the unittests where the generator is 
initialized with implicit construction, versus where the default 
seed is explicitly supplied:
https://github.com/WebDrake/mersenne-twister-range/blob/dda0bb006ee4633ae4fa227f9bad1453ba0e9885/src/mersenne_twister_range.d#L399-L407

... different results emerge when compiled with dmd; it turns out 
that in the implicit-construction case, only the `state.z` 
variable is set (the rest are all zeroes), whereas with the 
explicit seeding, all elements of the `state` variable are set 
correctly.

When ldc2 is used, this doesn't happen and in both cases the 
`state` variable is set correctly.

Can anyone advise what could be going wrong here?  This looks 
like a nasty CTFE bug to me :-(

Thanks & best wishes,

     -- Joe


More information about the Digitalmars-d-learn mailing list