| 51 | }; |
| 52 | |
| 53 | TEST_F(TestIndCallSolverMgr, getCalledFunctionP) { |
| 54 | std::string Code = "extern \"C\" {\n" |
| 55 | "void func1(void);\n" |
| 56 | "void func2(void);\n" |
| 57 | "void func3(int);\n" |
| 58 | "char func4(void);\n" |
| 59 | "char (*GVar)(void) = func4;\n" |
| 60 | "void func5(char);\n" |
| 61 | "void func6(char);\n" |
| 62 | "class CLS1 {\n" |
| 63 | "public:\n" |
| 64 | " virtual void M() { func5('a'); }\n" |
| 65 | "};\n" |
| 66 | "class CLS2 : public CLS1 {\n" |
| 67 | "public:\n" |
| 68 | " void M() { func6('b'); }\n" |
| 69 | "};\n" |
| 70 | "void test_direct_call() {\n" |
| 71 | " func1();\n" |
| 72 | "}" |
| 73 | "void test_callee_metadata() {\n" |
| 74 | " void (*Var1)(void) = func2;\n" |
| 75 | " Var1();\n" |
| 76 | "}\n" |
| 77 | "void test_inst(void (*P)(int)) {\n" |
| 78 | " void (*Var)(int) = func3;\n" |
| 79 | " P(10);\n" |
| 80 | "}\n" |
| 81 | "void test_global(char (*P)(void)) {\n" |
| 82 | " P();\n" |
| 83 | "}\n" |
| 84 | "void test_virt() {\n" |
| 85 | " CLS1 *Var = new CLS2();\n" |
| 86 | " Var->M();\n" |
| 87 | "}\n" |
| 88 | "}"; |
| 89 | ASSERT_TRUE(loadCPP(Code, CompileOpt)); |
| 90 | |
| 91 | IndCallSolverMgr Solver; |
| 92 | Solver.solve(*const_cast<Module *>(&SC->getLLVMModule())); |
| 93 | |
| 94 | ASSERT_TRUE(found(Solver, "test_direct_call", 0, 0, {"func1"})); |
| 95 | ASSERT_TRUE(found(Solver, "test_callee_metadata", 0, 5, {"func2"})); |
| 96 | ASSERT_TRUE(found(Solver, "test_inst", 0, 7, {"func3"})); |
| 97 | ASSERT_TRUE(found(Solver, "test_global", 0, 3, {"func4"})); |
| 98 | ASSERT_TRUE( |
| 99 | found(Solver, "test_virt", 0, 18, {"_ZN4CLS11MEv", "_ZN4CLS21MEv"})); |
| 100 | } |
| 101 | |
| 102 | TEST_F(TestIndCallSolverMgr, getCalledFunctionN) { |
| 103 | std::string Code = "extern \"C\" {\n" |
nothing calls this directly
no test coverage detected