[Issue 8790] New: Compiling with optimization produces erroneous variable initialization error

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Oct 9 18:05:08 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=8790

           Summary: Compiling with optimization produces erroneous
                    variable initialization error
           Product: D
           Version: D2
          Platform: All
        OS/Version: Linux
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: hsteoh at quickfur.ath.cx


--- Comment #0 from hsteoh at quickfur.ath.cx 2012-10-09 17:41:02 PDT ---
import std.algorithm;
import std.range;

void main() {
    auto N2 = sequence!"n"(cast(size_t)1).map!"a";
}


When compiling with dmd -O (latest git for dmd, druntime, phobos), this
produces the following errors:

/usr/src/d/phobos/std/range.d(4590): Error: variable upper used before set
/usr/src/d/phobos/std/range.d(4590): Error: variable lower used before set

The referenced line of code occurs in this context:

    auto opSlice(size_t lower, size_t upper)
    in
    {  
        assert(upper >= lower); // this is line 4590
    }
    body
    {  
        auto s = typeof(this)(this._state, this._n + lower);
        return takeExactly(s, upper - lower);
    }

Which makes no sense, because there is nothing wrong with the reference to
upper and lower (they are function parameters). Perhaps the optimizer
inadvertently permuted the order of stuff in a way that caused the contract to
run before the parameters are initialized?

If -O is not specified, the compile is successful. This problem appears to be
independent of whether I specify -m32 or -m64.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list