dmd -O produces incorrect code?

1100110 0b1100110 at gmail.com
Sun Feb 10 19:26:36 PST 2013


On 02/10/2013 07:14 PM, 1100110 wrote:
> I've taken std.mmfile, and been playing with it.
>
> I won't lie, mostly I've just been messing with it.
> The idea was originally to fix opDollar for mmfile (which I can push if
> it will be accepted.)
>
> I turned it into a template for funsies.
> And a struct. For funsies.
>
> And it Works! mostly.
>
> But only if you don't compile with -O.
> -release works, -inline works, -noboundscheck works.
>
> heres an example:
> ---
> import std.conv, std.stdio;
> void main()
> {
> auto mm = mmFile!string("mmTest.d");
> string mt = mm[0..50];
> string ms = mt[0..50];
> string ss = mm.data;
>
> writeln(mm[0..$]);//prints the entire file.
> writeln(ms);//prints the first 50 characters.
>
> writeln(mm.data.ptr);//data is the internal string.
> writeln(ms.ptr);//all of these should be equal.
> writeln(mt.ptr);//But this one and the one above are not.
> writeln(ss.ptr);//also nothing gets printed with -O, it segfaults.
>
> return;
> }
> --
>
> Here is an example output with rdmd mmTest.d:
> //the above file[0..$]
> //the about file[0..50]
> 7F47535F5000
> 7F47535F5000
> 7F47535F5000
> 7F47535F5000
>
> Here is outut with rdmd -O mmTest.d:
> �
> �
> 7FEA61B77000
> 406470
> 406470
> 7FEA61B77000
>
> What's up with that?

Found it! I was destroy(class) manually allocated class.
That was my fault. Completely.  I knew I would be embarrassed if I 
posted this.  =P

I am now in love with cgdb.
Go get it.  It's beautiful.


More information about the Digitalmars-d mailing list