@@ -26,7 +26,7 @@ void g(int i) {
26
26
printf (" %d" , i);
27
27
}
28
28
29
- int vfn = 0 ;
29
+ int uuid = 0 ;
30
30
char base_present[N_STRUCTS][N_STRUCTS];
31
31
32
32
bool is_ambiguous (int s, int base) {
@@ -119,12 +119,15 @@ void gs(int s) {
119
119
120
120
/* Virtual functions */
121
121
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 ;
123
126
int old_func = -1 ;
124
127
for (int i = 0 ; i < n_funcs; ++i) {
125
128
int fn = old_func + random () % FUNCSPACING + 1 ;
126
129
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 (" ); }" );
128
131
old_func = fn;
129
132
}
130
133
@@ -154,23 +157,25 @@ void gs(int s) {
154
157
for (int i = 0 ; i < n_bases; ++i) {
155
158
g (" if ((char *)dynamic_cast<s" ); g (bases[i]); gl (" *>(this))" );
156
159
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 ( " );" );
158
161
}
159
162
}
160
163
161
164
/* check field layout */
162
165
for (int i = 0 ; i < n_fields; ++i) {
163
166
g (" mix(\" field offset\" , (char *)&field" ); g (i); gl (" - (char *)this);" );
164
167
}
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
+ }
167
171
168
172
/* check functions */
169
173
for (int i = 0 ; i < n_funcs; ++i) {
170
174
g (" fun" ); g (funcs[i]); gl (" (t);" );
171
175
}
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
+ }
174
179
175
180
gl (" }" );
176
181
0 commit comments