[Bug 187] New: Nested struct that has non-padded array does not initialize fields correctly when compiled with optimizations
via D.gnu
d.gnu at puremagic.com
Thu May 21 03:06:05 PDT 2015
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 at gdcproject.org
Reporter: liran at 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:
bash-4.3# /opt/gdc/bin/gdc -ggdb -O -ogtest test.d && ./gtest
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/d.gnu/attachments/20150521/c0e718cd/attachment.html>
More information about the D.gnu
mailing list