DMD optimization bug?
Jacob Carlborg
doob at me.com
Fri Mar 22 00:26:57 PDT 2013
On 2013-03-21 22:46, Iain Buclaw wrote:
> On 21 March 2013 20:29, Jacob Carlborg <doob at me.com
> <mailto:doob at me.com>> wrote:
>
> The code below works fine without optimizations. But with
> optimizations (the -O flag) turned on it segfaults. The behavior
> with optimizations turned on is a bit different depending on which
> version of DMD I try and if I compile for 32 or 64bit.
>
> DMD 2.062 64bit: Segfault
> DMD 2.062 32bit: Prints a huge array then segfault
> DMD 2.061 64bit: Segfault
> DMD 2.061 32bit: Prints a fairly small array (10 elements) with
> random numbers
> DMD head (7dcc72a997) 32bit: Bus error: 10
>
> I'm using Mac OS X 10.8.2.
>
> import std.stdio;
>
> int[]* getDeserializedSlice ()
> {
> void[] a = [1, 2, 3, 4, 5].dup;
> auto b = &a;
>
> if (auto c = b)
> auto d = &(cast(int[]) *c)[1 .. 1 + 2];
>
> return null;
> }
>
> void main ()
> {
> writeln(*getDeserializedSlice(__));
> }
>
> Is the above code supposed to work? The test case might look a bit
> strange, the full source code is here:
>
> https://github.com/jacob-__carlborg/orange/blob/master/__orange/serialization/__Serializer.d#L1672
> <https://github.com/jacob-carlborg/orange/blob/master/orange/serialization/Serializer.d#L1672>
>
> --
> /Jacob Carlborg
Crap, that example was incorrect, it should look like this:
return &(cast(int[]) *c)[1 .. 1 + 2];
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list