1 // RUN: %clangxx_cfi -c -DTU1 -o %t1.o %s
2 // RUN: %clangxx_cfi -c -DTU2 -o %t2.o %S/../cfi/anon-namespace.cpp
3 // RUN: %clangxx_cfi -o %t1 %t1.o %t2.o
4 // RUN: %expect_crash %run %t1 2>&1 | FileCheck --check-prefix=CFI %s
6 // RUN: %clangxx_cfi -c -DTU1 -DB32 -o %t1.o %s
7 // RUN: %clangxx_cfi -c -DTU2 -DB32 -o %t2.o %S/../cfi/anon-namespace.cpp
8 // RUN: %clangxx_cfi -o %t2 %t1.o %t2.o
9 // RUN: %expect_crash %run %t2 2>&1 | FileCheck --check-prefix=CFI %s
11 // RUN: %clangxx_cfi -c -DTU1 -DB64 -o %t1.o %s
12 // RUN: %clangxx_cfi -c -DTU2 -DB64 -o %t2.o %S/../cfi/anon-namespace.cpp
13 // RUN: %clangxx_cfi -o %t3 %t1.o %t2.o
14 // RUN: %expect_crash %run %t3 2>&1 | FileCheck --check-prefix=CFI %s
16 // RUN: %clangxx_cfi -c -DTU1 -DBM -o %t1.o %s
17 // RUN: %clangxx_cfi -c -DTU2 -DBM -o %t2.o %S/../cfi/anon-namespace.cpp
18 // RUN: %clangxx_cfi -o %t4 %t1.o %t2.o
19 // RUN: %expect_crash %run %t4 2>&1 | FileCheck --check-prefix=CFI %s
21 // RUN: %clangxx -c -DTU1 -o %t1.o %s
22 // RUN: %clangxx -c -DTU2 -o %t2.o %S/../cfi/anon-namespace.cpp
23 // RUN: %clangxx -o %t5 %t1.o %t2.o
24 // RUN: %run %t5 2>&1 | FileCheck --check-prefix=NCFI %s
26 // RUN: %clangxx_cfi_diag -c -DTU1 -o %t1.o %s
27 // RUN: %clangxx_cfi_diag -c -DTU2 -o %t2.o %S/../cfi/anon-namespace.cpp
28 // RUN: %clangxx_cfi_diag -o %t6 %t1.o %t2.o
29 // RUN: %run %t6 2>&1 | FileCheck --check-prefix=CFI-DIAG %s
31 // Tests that the CFI mechanism treats classes in the anonymous namespace in
32 // different translation units as having distinct identities. This is done by
33 // compiling two translation units TU1 and TU2 containing a class named B in an
34 // anonymous namespace, and testing that the program crashes if TU2 attempts to
35 // use a TU1 B as a TU2 B.
37 // FIXME: This test should not require that the paths supplied to the compiler
38 // are different. It currently does so because bitset names have global scope
39 // so we have to mangle the file path into the bitset name.
74 break_optimization(a
);
78 fprintf(stderr
, "1\n");
80 // CFI-DIAG: runtime error: control flow integrity check for type '(anonymous namespace)::B' failed during base-to-derived cast
81 // CFI-DIAG-NEXT: note: vtable is of type '{{.*}}anonymous namespace{{.*}}::B'
82 // CFI-DIAG: runtime error: control flow integrity check for type '(anonymous namespace)::B' failed during virtual call
83 // CFI-DIAG-NEXT: note: vtable is of type '{{.*}}anonymous namespace{{.*}}::B'
84 ((B
*)a
)->f(); // UB here
88 fprintf(stderr
, "2\n");