Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 82f0be9

Browse files
author
Mike Stump
committed
1/2 off all structs should not have any virtual functions.
Replace magic numbers with uuids. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92941 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 365d638 commit 82f0be9

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

utils/VtableTest/gen.cc

+13-8
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void g(int i) {
2626
printf("%d", i);
2727
}
2828

29-
int vfn = 0;
29+
int uuid = 0;
3030
char base_present[N_STRUCTS][N_STRUCTS];
3131

3232
bool is_ambiguous(int s, int base) {
@@ -119,12 +119,15 @@ void gs(int s) {
119119

120120
/* Virtual functions */
121121
static int funcs[N_FUNCS];
122-
int n_funcs = random() % N_FUNCS;
122+
// PARAM: 1/2 of all structs should have no virtual functions
123+
int n_funcs = random() % (N_FUNCS*2);
124+
if (n_funcs > N_FUNCS)
125+
n_funcs = 0;
123126
int old_func = -1;
124127
for (int i = 0; i < n_funcs; ++i) {
125128
int fn = old_func + random() % FUNCSPACING + 1;
126129
funcs[i] = fn;
127-
g(" virtual void fun"); g(fn); g("(char *t) { mix(\"vfn this offset\", (char *)this - t); mix(\"vfn uuid\", "); g(++vfn); gl("); }");
130+
g(" virtual void fun"); g(fn); g("(char *t) { mix(\"vfn this offset\", (char *)this - t); mix(\"vfn uuid\", "); g(++uuid); gl("); }");
128131
old_func = fn;
129132
}
130133

@@ -154,23 +157,25 @@ void gs(int s) {
154157
for (int i = 0; i < n_bases; ++i) {
155158
g(" if ((char *)dynamic_cast<s"); g(bases[i]); gl("*>(this))");
156159
g(" mix(\"base dyn cast\", t - (char *)dynamic_cast<s"); g(bases[i]); gl("*>(this));");
157-
gl(" else mix(\"no dyncast\", 666);");
160+
g(" else mix(\"no dyncast\", "); g(++uuid); gl(");");
158161
}
159162
}
160163

161164
/* check field layout */
162165
for (int i = 0; i < n_fields; ++i) {
163166
g(" mix(\"field offset\", (char *)&field"); g(i); gl(" - (char *)this);");
164167
}
165-
if (n_fields == 0)
166-
gl(" mix(\"no fields\", 42);");
168+
if (n_fields == 0) {
169+
g(" mix(\"no fields\", "); g(++uuid); gl(");");
170+
}
167171

168172
/* check functions */
169173
for (int i = 0; i < n_funcs; ++i) {
170174
g(" fun"); g(funcs[i]); gl("(t);");
171175
}
172-
if (n_funcs == 0)
173-
gl(" mix(\"no funcs\", 13);");
176+
if (n_funcs == 0) {
177+
g(" mix(\"no funcs\", "); g(++uuid); gl(");");
178+
}
174179

175180
gl(" }");
176181

0 commit comments

Comments
 (0)