[cfe-commits] r93022 - in /cfe/trunk/utils/VtableTest: check-zti check-ztt check-zvt gen.cc
Mike Stump
mrs at apple.com
Fri Jan 8 11:25:37 PST 2010
Author: mrs
Date: Fri Jan 8 13:25:36 2010
New Revision: 93022
URL: http://llvm.org/viewvc/llvm-project?rev=93022&view=rev
Log:
Add in final overrider logic.
Modified:
cfe/trunk/utils/VtableTest/check-zti
cfe/trunk/utils/VtableTest/check-ztt
cfe/trunk/utils/VtableTest/check-zvt
cfe/trunk/utils/VtableTest/gen.cc
Modified: cfe/trunk/utils/VtableTest/check-zti
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/VtableTest/check-zti?rev=93022&r1=93021&r2=93022&view=diff
==============================================================================
--- cfe/trunk/utils/VtableTest/check-zti (original)
+++ cfe/trunk/utils/VtableTest/check-zti Fri Jan 8 13:25:36 2010
@@ -4,7 +4,7 @@
# Utility routine to "hand" check type infos.
-let i=0;
+let i=1;
while [ $i != $N_STRUCTS ]; do
sed -n "/^__ZTI.*s$i:/,/\.[sg][el]/p" test-clang.s |
grep -v '\.[sg][el]' | sed 's/(\([0-9][0-9]*\))/\1/' >test-clang-zti
Modified: cfe/trunk/utils/VtableTest/check-ztt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/VtableTest/check-ztt?rev=93022&r1=93021&r2=93022&view=diff
==============================================================================
--- cfe/trunk/utils/VtableTest/check-ztt (original)
+++ cfe/trunk/utils/VtableTest/check-ztt Fri Jan 8 13:25:36 2010
@@ -4,7 +4,7 @@
# Utility routine to "hand" check VTTs.
-let i=0;
+let i=1;
while [ $i != $N_STRUCTS ]; do
sed -n "/^__ZTT.*s$i:/,/\.[sg][el]/p" test-clang.s |
grep -v '\.[sg][el]' | sed 's/(\([0-9][0-9]*\))/\1/' >test-clang-ztt
Modified: cfe/trunk/utils/VtableTest/check-zvt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/VtableTest/check-zvt?rev=93022&r1=93021&r2=93022&view=diff
==============================================================================
--- cfe/trunk/utils/VtableTest/check-zvt (original)
+++ cfe/trunk/utils/VtableTest/check-zvt Fri Jan 8 13:25:36 2010
@@ -4,7 +4,7 @@
# Utility routine to "hand" check vtables.
-let i=0;
+let i=1;
while [ $i != $N_STRUCTS ]; do
sed -n "/^__ZTV.*s$i:/,/\.[sg][el]/p" test-clang.s | grep -v '\.[sg][el]' >test-clang-ztv
sed -n "/^__ZTV.*s$i:/,/\.[sg][el]/p" test-gcc.s | grep -v '\.[sg][el]' >test-gcc-ztv
Modified: cfe/trunk/utils/VtableTest/gen.cc
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/VtableTest/gen.cc?rev=93022&r1=93021&r2=93022&view=diff
==============================================================================
--- cfe/trunk/utils/VtableTest/gen.cc (original)
+++ cfe/trunk/utils/VtableTest/gen.cc Fri Jan 8 13:25:36 2010
@@ -5,9 +5,7 @@
#define N_FUNCS 128
#define FUNCSPACING 10
#define N_STRUCTS 300 /* 1280 */
-// FIXME: Need final overrider logic for 3 or more if we turn on virtual base
-// class dups
-#define N_BASES 30 /* 30 */
+#define N_BASES 30
const char *simple_types[] = { "bool", "char", "short", "int", "float",
"double", "long double", "wchar_t", "void *",
@@ -28,12 +26,11 @@
int uuid = 0;
char base_present[N_STRUCTS][N_STRUCTS];
+char funcs_present[N_STRUCTS][N_FUNCS*FUNCSPACING];
bool is_ambiguous(int s, int base) {
for (int i = 0; i < N_STRUCTS; ++i) {
- if ((base_present[base][i] & base_present[s][i])
- // FIXME: todo this, we need final overrider additions
- /*== 1 */)
+ if ((base_present[base][i] & base_present[s][i]) == 1)
return true;
}
return false;
@@ -44,6 +41,10 @@
base_present[s][i] |= base_present[base][i];
}
+// This contains the class that has the final override for
+// each class, for each function.
+short final_override[N_STRUCTS][N_FUNCS*FUNCSPACING];
+
void gs(int s) {
bool polymorphic = false;
@@ -62,11 +63,11 @@
g("class s");
g(s);
int old_base = -1;
- if (s == 0)
+ if (s == 0 || s == 1)
i_bases = 0;
while (i_bases) {
--i_bases;
- int base = random() % s;
+ int base = random() % (s-1) + 1;
if (!base_present[s][base]) {
if (is_ambiguous(s, base))
continue;
@@ -79,7 +80,8 @@
if (random()%8 == 0) {
// PARAM: 1/8th the bases are virtual
g("virtual ");
- polymorphic = true;
+ // We have a vtable and rtti, but technically we're not polymorphic
+ // polymorphic = true;
base_type = 3;
}
switch (random()%8) {
@@ -118,7 +120,7 @@
}
/* Virtual functions */
- static int funcs[N_FUNCS];
+ static int funcs[N_FUNCS*FUNCSPACING];
// PARAM: 1/2 of all structs should have no virtual functions
int n_funcs = random() % (N_FUNCS*2);
if (n_funcs > N_FUNCS)
@@ -128,9 +130,65 @@
int fn = old_func + random() % FUNCSPACING + 1;
funcs[i] = fn;
g(" virtual void fun"); g(fn); g("(char *t) { mix(\"vfn this offset\", (char *)this - t); mix(\"vfn uuid\", "); g(++uuid); gl("); }");
+ funcs_present[s][fn] = 1;
+ final_override[s][fn] = s;
old_func = fn;
}
+ // Add required overriders for correctness
+ for (int i = 0; i < n_bases; ++i) {
+ // For each base
+ int base = bases[i];
+ for (int fn = 0; fn < N_FUNCS*FUNCSPACING; ++fn) {
+ // For each possible function
+ int new_base = final_override[base][fn];
+ if (new_base == 0)
+ // If the base didn't have a final overrider, skip
+ continue;
+
+ int prev_base = final_override[s][fn];
+ if (prev_base == s)
+ // Skip functions defined in this class
+ continue;
+
+ // If we don't want to change the info, skip
+ if (prev_base == new_base)
+ continue;
+
+ if (prev_base == 0) {
+ // record the final override
+ final_override[s][fn] = new_base;
+ continue;
+ }
+
+ if (base_present[prev_base][new_base]) {
+ // The previous base dominates the new base, no update necessary
+ fprintf(stderr, "// No override for fun%d in s%d as s%d dominates s%d.\n",
+ fn, s, prev_base, new_base);
+ continue;
+ }
+
+ if (base_present[new_base][prev_base]) {
+ // The new base dominates the old base, no override necessary
+ fprintf(stderr, "// No override for fun%d in s%d as s%d dominates s%d.\n",
+ fn, s, new_base, prev_base);
+ // record the final override
+ final_override[s][fn] = new_base;
+ continue;
+ }
+
+ printf("// Found we needed override for fun%d in s%d.\n", fn, s);
+
+ // record the final override
+ funcs[n_funcs++] = fn;
+ if (n_funcs == (N_FUNCS*FUNCSPACING-1))
+ abort();
+ g(" virtual void fun"); g(fn); g("(char *t) { mix(\"vfn this offset\", (char *)this - t); mix(\"vfn uuid\", "); g(++uuid); gl("); }");
+ funcs_present[s][fn] = 1;
+ final_override[s][fn] = s;
+ }
+ }
+
gl("public:");
gl(" void calc(char *t) {");
@@ -218,7 +276,7 @@
gl("");
// PARAM: Randomly size testcases or large testcases?
int n_structs = /* random() % */ N_STRUCTS;
- for (int i = 0; i < n_structs; ++i)
+ for (int i = 1; i < n_structs; ++i)
gs(i);
gl("int main() {");
gl(" printf(\"%llx\\n\", sum);");
More information about the cfe-commits
mailing list