ada: Fix internal error on instantiation with private component type
[official-gcc.git] / libphobos / testsuite / libphobos.gc / precisegc.d
blob9bcaf3f4faad0de69227aabcb664d1d9b8f8214e
1 // precise GC related:
2 // https://issues.dlang.org/show_bug.cgi?id=3463
3 // https://issues.dlang.org/show_bug.cgi?id=4358
4 // https://issues.dlang.org/show_bug.cgi?id=9094
5 // https://issues.dlang.org/show_bug.cgi?id=13801
6 // https://issues.dlang.org/show_bug.cgi?id=18900
7 module testgc;
9 import core.memory;
10 import core.stdc.stdio;
12 class C
14 __gshared int dtors;
15 ~this() { dtors++; }
17 C next;
18 size_t val;
21 struct S
23 __gshared int dtors;
24 ~this() { dtors++; }
26 size_t val;
27 S* next;
30 struct L
32 __gshared int dtors;
33 ~this() { dtors++; }
35 size_t[1000] data;
36 S* node;
39 struct Roots
41 C c;
42 S *s;
43 L *l;
46 Roots* roots;
47 size_t iroots;
49 void init()
51 roots = new Roots;
52 roots.c = new C;
53 roots.c.next = new C;
55 roots.s = new S;
56 roots.s.next = new S;
58 roots.l = new L;
59 roots.l.node = new S;
62 void verifyPointers()
64 assert(C.dtors == 0);
65 assert(S.dtors == 0);
66 assert(L.dtors == 0);
69 // compiling with -gx should help eliminating false pointers on the stack
70 Roots makeFalsePointers()
72 roots.c.val = cast(size_t) cast(void*) roots.c.next;
73 roots.c.next = null;
74 roots.s.val = cast(size_t) cast(void*) roots.s.next;
75 roots.s.next = null;
76 roots.l.data[7] = cast(size_t) cast(void*) roots.l.node;
77 roots.l.node = null;
79 return Roots(null, null, null); // try to spill register contents
82 Roots moveRoot()
84 iroots = cast(size_t)roots;
85 roots = null;
87 return Roots(null, null, null); // try to spill register contents
90 // compiling with -gx should help eliminating false pointers on the stack
91 void verifyFalsePointers()
93 assert(C.dtors <= 1);
94 if (C.dtors < 1) printf ("False pointers? C.dtors = %d, 1 expected\n", C.dtors);
95 assert(S.dtors <= 2);
96 if (S.dtors < 2) printf ("False pointers? S.dtors = %d, 2 expected\n", S.dtors);
97 assert(L.dtors == 0);
100 extern(C) __gshared string[] rt_options = [ "gcopt=gc:precise", "scanDataSeg=precise" ];
102 void main()
104 GC.collect(); // cleanup from unittests
106 init();
107 GC.collect(); // should collect nothing
108 verifyPointers();
110 makeFalsePointers();
111 GC.collect(); // should collect roots.c.next, roots.s.next and roots.l.node
112 verifyFalsePointers();
114 moveRoot();
115 GC.collect(); // should collect all
117 version(Windows) // precise DATA scanning only implemented on Windows
119 assert(C.dtors <= 2);
120 if (C.dtors < 2) printf ("False DATA pointers? C.dtors = %d, 2 expected\n", C.dtors);
121 assert(S.dtors <= 3);
122 if (S.dtors < 3) printf ("False DATA pointers? S.dtors = %d, 2 expected\n", S.dtors);
123 assert(L.dtors <= 1);
124 if (L.dtors < 1) printf ("False DATA pointers? L.dtors = %d, 1 expected\n", L.dtors);