Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / cfi / cross-dso-diagnostic.cpp
blobf0a2ab4459c5f5d82477fb0f9e9398d858727d0f
1 // Check that cross-DSO diagnostics print the names of both modules
3 // RUN: %clangxx_cfi_diag -g -DSHARED_LIB -fPIC -shared -o %dynamiclib %s %ld_flags_rpath_so
4 // RUN: %clangxx_cfi_diag -g -o %t_exe_suffix %s %ld_flags_rpath_exe
5 // RUN: %t_exe_suffix 2>&1 | FileCheck -DDSONAME=%xdynamiclib_namespec %s
7 // UNSUPPORTED: target={{.*windows-msvc.*}}
8 // REQUIRES: cxxabi
10 #include <dlfcn.h>
11 #include <stdio.h>
13 struct S1 {
14 virtual void f1();
17 #ifdef SHARED_LIB
19 void S1::f1() {}
21 __attribute__((visibility("default"))) extern "C"
22 void* dso_symbol() { return new S1(); }
24 #else
26 int main() {
27 void* (*fp)(void) =
28 reinterpret_cast<void*(*)(void)>(dlsym(RTLD_DEFAULT, "dso_symbol"));
29 if (!fp) {
30 perror("failed to resolve dso_symbol");
31 return 1;
34 // CHECK: runtime error: control flow integrity check for type 'void *()' failed during indirect function call
35 // CHECK: dso_symbol defined here
36 // CHECK: check failed in {{.*}}_exe_suffix, destination function located in {{.*}}[[DSONAME]]
37 void *S = fp(); // trigger cfi-icall failure
39 // CHECK: runtime error: control flow integrity check for type 'S1' failed during cast to unrelated type
40 // CHECK: invalid vtable
41 // CHECK: check failed in {{.*}}_exe_suffix, vtable located in {{.*}}[[DSONAME]]
42 S1 *Scast = reinterpret_cast<S1*>(S); // trigger cfi-unrelated-cast failure
44 return 0;
47 #endif // SHARED_LIB