[Issue 10966] Leaked destruction in static array postblit
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Sep 5 02:07:11 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10966
Kenji Hara <k.hara.pg at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
Severity|normal |critical
--- Comment #1 from Kenji Hara <k.hara.pg at gmail.com> 2013-09-05 02:07:08 PDT ---
This is -O switch issue with dmd.
Test following reduced case.
--------
extern(C) int printf(const char*, ...);
int k;
struct S
{
int a;
this(this)
{
printf("postblitting %d... ", a);
if (k++ == 2)
{
printf("FAILED!\n");
throw new Exception("BOOM!");
}
a += 10;
printf("OK => %d\n", a);
}
~this()
{
printf("destroying %d\n", a);
}
}
void main()
{
S s0 = S(0);
S[4] ss1 = [S(1), S(2), S(3), S(4)];
S[4] ss2 = s0; //Case 1 to N
// call _d_arraysetctor defined in this module
// instead of the one stored in druntime
}
// copy from druntime/src/rt/arrayassign.d
extern (C) void* _d_arraysetctor(void* p, void* value, int count, TypeInfo ti)
{
import core.stdc.string : memcpy;
void* pstart = p; // with -O, variable pstart is wrongly made an alias of
p
auto element_size = ti.tsize;
try
{
foreach (i; 0 .. count)
{
// Copy construction is defined as bit copy followed by postblit.
memcpy(p, value, element_size);
ti.postblit(p);
p += element_size;
}
}
catch (Throwable o)
{
// Destroy, in reverse order, what we've constructed so far
while (p > pstart)
{
p -= element_size;
ti.destroy(p);
}
printf("--end\n");
throw o;
}
return pstart;
}
--------
Without -O switch, _d_arraysetctor works as expected.
With -O switch, it doesn't work correctly.
Today druntime is normally compiled with -O switch, therefore this problem
occurs always.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list