Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / ignore_lib1.cpp
blobc8cd3f466410072122d80ed1524526ab8de44353
1 // RUN: rm -rf %t-dir
2 // RUN: mkdir %t-dir
4 // RUN: %clangxx_tsan -O1 -fno-builtin %s -DLIB -fPIC -fno-sanitize=thread -shared -o %t-dir/libignore_lib1.so
5 // RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -o %t-dir/executable
6 // RUN: echo running w/o suppressions:
7 // RUN: %deflake %run %t-dir/executable | FileCheck %s --check-prefix=CHECK-NOSUPP
8 // RUN: echo running with suppressions:
9 // RUN: %env_tsan_opts=suppressions='%s.supp' %run %t-dir/executable 2>&1 | FileCheck %s --check-prefix=CHECK-WITHSUPP
11 // Tests that interceptors coming from a dynamically loaded library specified
12 // in called_from_lib suppression are ignored.
14 // REQUIRES: stable-runtime
15 // UNSUPPORTED: target=powerpc64le{{.*}}
16 // FIXME: This test regularly fails on powerpc64 LE possibly starting with
17 // r279664. Re-enable the test once the problem(s) have been fixed.
19 #ifndef LIB
21 #include <dlfcn.h>
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <errno.h>
25 #include <libgen.h>
26 #include <string>
28 int main(int argc, char **argv) {
29 std::string lib = std::string(dirname(argv[0])) + "/libignore_lib1.so";
30 void *h = dlopen(lib.c_str(), RTLD_GLOBAL | RTLD_NOW);
31 if (h == 0)
32 exit(printf("failed to load the library (%d)\n", errno));
33 void (*f)() = (void(*)())dlsym(h, "libfunc");
34 if (f == 0)
35 exit(printf("failed to find the func (%d)\n", errno));
36 f();
39 #else // #ifdef LIB
41 #include "ignore_lib_lib.h"
43 #endif // #ifdef LIB
45 // CHECK-NOSUPP: WARNING: ThreadSanitizer: data race
46 // CHECK-NOSUPP: OK
48 // CHECK-WITHSUPP-NOT: WARNING: ThreadSanitizer: data race
49 // CHECK-WITHSUPP: OK