1
0
mirror of https://github.com/alliedmodders/metamod-source.git synced 2024-12-01 13:24:25 +01:00

Fix testvphooks.

This commit is contained in:
David Anderson 2015-09-24 21:03:21 -07:00
parent 9302296462
commit 219cd7203f
3 changed files with 33 additions and 7 deletions

View File

@ -109,6 +109,19 @@ namespace
SH_DECL_MANUALHOOK1_void(IBase_Func3_Manual, 2, 0, 0, int); SH_DECL_MANUALHOOK1_void(IBase_Func3_Manual, 2, 0, 0, int);
} }
// Clang is smart enough to see:
// CDerived1 a;
// IBase *p = &a;
// p->Func1()
//
// May bypass the vtable, since p_d1i2 has exactly one assignment. We try to
// defeat the analysis that produces this result here.
template <typename T>
T defeat_ssa(const T& t)
{
return time(NULL) ? t : nullptr;
}
bool TestVPHooks(std::string &error) bool TestVPHooks(std::string &error)
{ {
GET_SHPTR(g_SHPtr); GET_SHPTR(g_SHPtr);
@ -118,9 +131,9 @@ bool TestVPHooks(std::string &error)
CDerived1 d1i2; CDerived1 d1i2;
CDerived2 d2i1; CDerived2 d2i1;
IBase *p_d1i1 = &d1i1; IBase *p_d1i1 = defeat_ssa(&d1i1);
IBase *p_d1i2 = &d1i2; IBase *p_d1i2 = defeat_ssa(&d1i2);
IBase *p_d2i1 = &d2i1; IBase *p_d2i1 = defeat_ssa(&d2i1);
int hook1 = SH_ADD_VPHOOK(IBase, Func1, p_d1i1, SH_STATIC(Handler_Func1_Pre), false); int hook1 = SH_ADD_VPHOOK(IBase, Func1, p_d1i1, SH_STATIC(Handler_Func1_Pre), false);

View File

@ -71,7 +71,7 @@ int main(int argc, char *argv[])
DO_TEST(Multi); DO_TEST(Multi);
DO_TEST(Ref); DO_TEST(Ref);
DO_TEST(RefRet); DO_TEST(RefRet);
// DO_TEST(VPHooks); -- Known failures DO_TEST(VPHooks);
DO_TEST(CPageAlloc); DO_TEST(CPageAlloc);
DO_TEST(HookManGen); DO_TEST(HookManGen);
DO_TEST(OddThunks); DO_TEST(OddThunks);

View File

@ -109,6 +109,19 @@ namespace
SH_DECL_MANUALHOOK1_void(IBase_Func3_Manual, 2, 0, 0, int); SH_DECL_MANUALHOOK1_void(IBase_Func3_Manual, 2, 0, 0, int);
} }
// Clang is smart enough to see:
// CDerived1 a;
// IBase *p = &a;
// p->Func1()
//
// May bypass the vtable, since p_d1i2 has exactly one assignment. We try to
// defeat the analysis that produces this result here.
template <typename T>
T defeat_ssa(const T& t)
{
return time(NULL) ? t : nullptr;
}
bool TestVPHooks(std::string &error) bool TestVPHooks(std::string &error)
{ {
GET_SHPTR(g_SHPtr); GET_SHPTR(g_SHPtr);
@ -118,9 +131,9 @@ bool TestVPHooks(std::string &error)
CDerived1 d1i2; CDerived1 d1i2;
CDerived2 d2i1; CDerived2 d2i1;
IBase *p_d1i1 = &d1i1; IBase *p_d1i1 = defeat_ssa(&d1i1);
IBase *p_d1i2 = &d1i2; IBase *p_d1i2 = defeat_ssa(&d1i2);
IBase *p_d2i1 = &d2i1; IBase *p_d2i1 = defeat_ssa(&d2i1);
int hook1 = SH_ADD_VPHOOK(IBase, Func1, p_d1i1, SH_STATIC(Handler_Func1_Pre), false); int hook1 = SH_ADD_VPHOOK(IBase, Func1, p_d1i1, SH_STATIC(Handler_Func1_Pre), false);