summaryrefslogtreecommitdiff
path: root/test/cfi/vtable-may-alias.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/cfi/vtable-may-alias.cpp')
-rw-r--r--test/cfi/vtable-may-alias.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/cfi/vtable-may-alias.cpp b/test/cfi/vtable-may-alias.cpp
new file mode 100644
index 000000000000..f63b53b8c9e6
--- /dev/null
+++ b/test/cfi/vtable-may-alias.cpp
@@ -0,0 +1,25 @@
+// RUN: %clangxx_cfi -o %t %s
+// RUN: %run %t
+
+// In this example, both __typeid_A_global_addr and __typeid_B_global_addr will
+// refer to the same address. Make sure that the compiler does not assume that
+// they do not alias.
+
+struct A {
+ virtual void f() = 0;
+};
+
+struct B : A {
+ virtual void f() {}
+};
+
+__attribute__((weak)) void foo(void *p) {
+ B *b = (B *)p;
+ A *a = (A *)b;
+ a->f();
+}
+
+int main() {
+ B b;
+ foo(&b);
+}