1 // RUN: %clangxx_cfi_diag -o %t %s
2 // RUN: %run %t 2>&1 | FileCheck %s
4 // This test checks that we don't generate two type checks,
5 // if two virtual calls are in the same function.
7 // UNSUPPORTED: target={{.*windows-msvc.*}}
10 // TODO(krasin): implement the optimization to not emit two type checks.
17 fprintf(stderr
, "Base::Foo\n");
21 fprintf(stderr
, "Base::Bar\n");
25 class Derived
: public Base
{
28 fprintf(stderr
, "Derived::Foo\n");
32 printf("Derived::Bar\n");
36 __attribute__((noinline
)) void print(Base
* ptr
) {
38 // Corrupt the vtable pointer. We expect that the optimization will
39 // check vtable before the first vcall then store it in a local
40 // variable, and reuse it for the second vcall. With no optimization,
41 // CFI will complain about the virtual table being corrupted.
42 *reinterpret_cast<void**>(ptr
) = 0;
54 // CHECK: Derived::Foo
55 // CHECK-NOT: runtime error
56 // CHECK: Derived::Bar