www.digitalmars.com         C & C++   DMDScript  

D.gnu - [Bug 211] New: Error: iteration 2305843009213693951 invokes

Date: Sun, 7 Feb 2016 20:52:08 +0000
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Bugzilla-URL: http://bugzilla.gdcproject.org/
Auto-Submitted: auto-generated

http://bugzilla.gdcproject.org/show_bug.cgi?id=3D211

            Bug ID: 211
           Summary: Error: iteration 2305843009213693951 invokes undefined
                    behavior
           Product: GDC
           Version: development
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: Normal
         Component: gdc
          Assignee: ibuclaw gdcproject.org
          Reporter: ibuclaw gdcproject.org

---
struct Array
{
    void setlength(size_t nlength)
    {
        foreach (ref val; ptr[nlength .. length])
            val =3D 0;
    }

    void insertBack()
    {
        setlength(length + 1);
    }

    size_t* ptr;
    size_t length;
}
---

This causes an warning/error to be emitted under optimizations. (-O2 -Werro=
r)

---
array.d: In function =E2=80=98insertBack=E2=80=99:
array.d:5:9: error: iteration 2305843009213693951 invokes undefined behavior
[-Werror=3Daggressive-loop-optimizations]
         foreach (ref val; ptr[nlength .. length])
         ^

array.d:5:9: note: within this loop
         foreach (ref val; ptr[nlength .. length])
         ^
---

This is the codegen:
---
while (1)
{
    ulong & val;

    if (!(__aggr40.length > __key41)) break;
    val =3D __aggr40.ptr + __key41 * 8;
    *val =3D 0;
    __key41 =3D __key41 + 1;
}
---

I think this could be vastly improved by initializing the reference directl=
y,
rather than via a modify expression.

--=20
You are receiving this mail because:
You are watching all bug changes.=
Feb 07 2016