www.digitalmars.com         C & C++   DMDScript  

D.gnu - [Bug 187] New: Nested struct that has non-padded array does not

Date: Thu, 21 May 2015 11:06:05 +0100
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"

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

            Bug ID: 187
           Summary: Nested struct that has non-padded array does not
                    initialize fields correctly when compiled with
                    optimizations
           Product: GDC
           Version: 4.9.x
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: Normal
         Component: gdc
          Assignee: ibuclaw gdcproject.org
          Reporter: liran weka.io

Reproducible on commit b022dd4cac195d85e9c3a6a37f2501a07ade455a from April 7th
on the 4.9 branch.

Consider the following code:
---------------
module test;
import std.stdio;

align(1) struct Unpadded {
    align(1) {
        uint unpaddedA;
        ushort unpaddedB;
    }
}

struct StructWithUnpaddedArray {
    Unpadded[3] unpaddedArray;
    // If initializer differs than ubyte.init then it does get inititalized
    // Naturally, the "= ubyte.init" part is not required for the bug to
reproduce
    ubyte wontInitialize = ubyte.init;
}

struct OuterStruct {
    StructWithUnpaddedArray interesting;
}


void prepareStack()
{
    byte[255] stackGarbage;
    foreach(i, ref b; stackGarbage) {
        b  = cast(byte)(-i);
    }
}

void main()
{
    prepareStack();
    auto a = OuterStruct(StructWithUnpaddedArray());
    writefln("Value is %s . wontInitialize is %s ", a,
a.interesting.wontInitialize);
}
-------------------------------
When compiled with optimization, the wontInitialize field ends up being 194,
instead of 0 as by the D spec.

This is the minimal code that I was able to get that reproduces.

example output:

Value is OuterStruct(StructWithUnpaddedArray([Unpadded(0, 0), Unpadded(0, 0),
Unpadded(0, 0)], 194)) . wontInitialize is 194

-- 
You are receiving this mail because:
You are watching all bug changes.
May 21 2015