<html>
<head>
<base href="http://bugzilla.gdcproject.org/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Nested struct that has non-padded array does not initialize fields correctly when compiled with optimizations"
href="http://bugzilla.gdcproject.org/show_bug.cgi?id=187">187</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Nested struct that has non-padded array does not initialize fields correctly when compiled with optimizations
</td>
</tr>
<tr>
<th>Product</th>
<td>GDC
</td>
</tr>
<tr>
<th>Version</th>
<td>4.9.x
</td>
</tr>
<tr>
<th>Hardware</th>
<td>x86_64
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>Normal
</td>
</tr>
<tr>
<th>Component</th>
<td>gdc
</td>
</tr>
<tr>
<th>Assignee</th>
<td>ibuclaw@gdcproject.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>liran@weka.io
</td>
</tr></table>
<p>
<div>
<pre>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</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are watching all bug changes.</li>
</ul>
</body>
</html>