mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 13:10:12 +03:00
add test case from #20853
This commit is contained in:
parent
28364abd38
commit
c4a9796472
1 changed files with 42 additions and 0 deletions
|
@ -40,6 +40,7 @@ void main()
|
||||||
testZeroSizedValue();
|
testZeroSizedValue();
|
||||||
testTombstonePurging();
|
testTombstonePurging();
|
||||||
testClear();
|
testClear();
|
||||||
|
testTypeInfoCollect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void testKeysValues1()
|
void testKeysValues1()
|
||||||
|
@ -905,3 +906,44 @@ void testClear()
|
||||||
assert(aa.length == 1);
|
assert(aa.length == 1);
|
||||||
assert(aa[5] == 6);
|
assert(aa[5] == 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/dlang/dmd/issues/17503
|
||||||
|
void testTypeInfoCollect()
|
||||||
|
{
|
||||||
|
import core.memory;
|
||||||
|
|
||||||
|
static struct S
|
||||||
|
{
|
||||||
|
int x;
|
||||||
|
~this() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct AAHolder
|
||||||
|
{
|
||||||
|
S[int] aa;
|
||||||
|
}
|
||||||
|
|
||||||
|
static S* getBadS()
|
||||||
|
{
|
||||||
|
auto aaholder = new AAHolder;
|
||||||
|
aaholder.aa[0] = S();
|
||||||
|
auto s = 0 in aaholder.aa; // keep a pointer to the entry
|
||||||
|
GC.free(aaholder); // but not a pointer to the AA.
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void stackStomp()
|
||||||
|
{
|
||||||
|
import core.stdc.string : memset;
|
||||||
|
ubyte[4 * 4096] x;
|
||||||
|
memset(x.ptr, 0, x.sizeof);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto s = getBadS();
|
||||||
|
stackStomp(); // destroy any stale references to the AA or s except in the current frame;
|
||||||
|
GC.collect(); // BUG: this used to invalidate the fake type info, should no longer do this.
|
||||||
|
foreach(i; 0 .. 1000) // try to reallocate the freed type info
|
||||||
|
auto p = new void*[1];
|
||||||
|
s = null; // clear any reference to the entry
|
||||||
|
GC.collect(); // used to segfault.
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue