Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / asan / TestCases / Linux / odr-violation.cpp
blob017aa4e12ce48007b721c76acf6aff3cf041b7c6
1 // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
2 // XFAIL: android
3 // Fails with debug checks: https://bugs.llvm.org/show_bug.cgi?id=46862
4 // XFAIL: !compiler-rt-optimized && !target=riscv64{{.*}}
5 //
6 // We use fast_unwind_on_malloc=0 to have full unwinding even w/o frame
7 // pointers. This setting is not on by default because it's too expensive.
8 //
9 // Note, -asan-use-private-alias=1 -asan-use-odr-indicator=1 is the default.
10 // -fno-sanitize-address-use-odr-indicator turns off both.
12 // Different size: detect a bug if detect_odr_violation>=1
13 // RUN: %clangxx_asan -g -DBUILD_SO=1 -fPIC -shared -fno-sanitize-address-use-odr-indicator %s -o %dynamiclib
14 // RUN: %clangxx_asan -g -fno-sanitize-address-use-odr-indicator %s %ld_flags_rpath_exe -o %t-ODR-EXE
15 // RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=1 not %run %t-ODR-EXE 2>&1 | FileCheck %s
16 // RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s
17 // RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=0 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
18 // RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t-ODR-EXE 2>&1 | FileCheck %s
20 // Same size: report a bug only if detect_odr_violation>=2.
21 // RUN: %clangxx_asan -g -DBUILD_SO=1 -fPIC -shared -fno-sanitize-address-use-odr-indicator %s -o %dynamiclib -DSZ=100
22 // RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=1 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
23 // RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s
24 // RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t-ODR-EXE 2>&1 | FileCheck %s
25 // RUN: echo "odr_violation:foo::ZZZ" > %t.supp
26 // RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2:suppressions=%t.supp not %run %t-ODR-EXE 2>&1 | FileCheck %s
27 // RUN: echo "odr_violation:foo::G" > %t.supp
28 // RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2:suppressions=%t.supp %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
29 // RUN: rm -f %t.supp
31 // Use private aliases for global variables without indicator symbol.
32 // RUN: %clangxx_asan -g -DBUILD_SO=1 -fPIC -shared -mllvm -asan-use-odr-indicator=0 %s -o %dynamiclib -DSZ=100
33 // RUN: %clangxx_asan -g -mllvm -asan-use-odr-indicator=0 %s %ld_flags_rpath_exe -o %t-ODR-EXE
34 // RUN: %env_asan_opts=fast_unwind_on_malloc=0 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
36 // Use private aliases for global variables: use indicator symbol to detect ODR violation.
37 // RUN: %clangxx_asan -g -DBUILD_SO=1 -fPIC -shared %s -o %dynamiclib -DSZ=100
38 // RUN: %clangxx_asan -g %s %ld_flags_rpath_exe -o %t-ODR-EXE
39 // RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t-ODR-EXE 2>&1 | FileCheck %s
41 // Same as above but with clang switches.
42 // RUN: %clangxx_asan -g -DBUILD_SO=1 -fPIC -shared -fsanitize-address-use-odr-indicator %s -o %dynamiclib -DSZ=100
43 // RUN: %clangxx_asan -g -fsanitize-address-use-odr-indicator %s %ld_flags_rpath_exe -o %t-ODR-EXE
44 // RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t-ODR-EXE 2>&1 | FileCheck %s
46 // GNU driver doesn't handle .so files properly.
47 // REQUIRES: Clang
49 // REQUIRES: fast-unwinder-works
51 #ifndef SZ
52 # define SZ 4
53 #endif
55 #if BUILD_SO
56 namespace foo { char G[SZ]; }
57 #else
58 #include <stdio.h>
59 namespace foo { char G[100]; }
60 // CHECK: ERROR: AddressSanitizer: odr-violation
61 // CHECK: size=100 'foo::G' {{.*}}odr-violation.cpp:[[@LINE-2]]
62 // CHECK: size={{4|100}} 'foo::G'
63 int main(int argc, char **argv) {
64 printf("PASS: %p\n", &foo::G);
66 #endif
68 // CHECK: These globals were registered at these points:
69 // CHECK: {{odr-violation.cpp|ODR-EXE}}
70 // CHECK: odr-violation.cpp{{$}}
71 // CHECK: SUMMARY: AddressSanitizer: odr-violation: global 'foo::G' at {{.*}}odr-violation.cpp
72 // DISABLED: PASS