dmd -O produces incorrect code?

1100110 0b1100110 at gmail.com
Sun Feb 10 17:14:12 PST 2013


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?


More information about the Digitalmars-d mailing list