www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17940] New: bool function parameters loaded from struct

https://issues.dlang.org/show_bug.cgi?id=17940

          Issue ID: 17940
           Summary: bool function parameters loaded from struct sometimes
                    miscompiled with -O
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: belka caraus.de

Code (test.d):

struct Array
{
    long length, ptr;
}

struct Struct
{
    bool b1 = true, b2;
}

void fun(Array arr, int, int)
{
    if (arr.length != 0) asm { int 3; }
}

void fn(Struct* str)
{
    Array arr;
    if (!str) return;
    if (str.b1)
    {
        fun(arr, str.b2, 0);
    }
    if (str.b1)
    {
        fun(arr, str.b1, 0);
    }
}

void main()
{
    Struct s;
    fn(&s);
}

Then:

dmd -O test.d  && ./test

causes "Trace/breakpoint trap"

--
Oct 26 2017