xref: /llvm-project/compiler-rt/test/cfi/vtable-may-alias.cpp (revision 868783e85557dde30923fab94c7ffabf5e271818)
1 // RUN: %clangxx_cfi -o %t %s
2 // RUN: %run %t
3 
4 // In this example, both __typeid_A_global_addr and __typeid_B_global_addr will
5 // refer to the same address. Make sure that the compiler does not assume that
6 // they do not alias.
7 
8 struct A {
9   virtual void f() = 0;
10 };
11 
12 struct B : A {
fB13   virtual void f() {}
14 };
15 
foo(void * p)16 __attribute__((weak)) void foo(void *p) {
17   B *b = (B *)p;
18   A *a = (A *)b;
19   a->f();
20 }
21 
main()22 int main() {
23   B b;
24   foo(&b);
25 }
26