[ASan] Improve ODR-violation error reports.
[blocksruntime.git] / test / asan / TestCases / Linux / odr-violation.cc
blobddc68a2db0f18fead33f7af355d661d267d4c2e0
1 // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
2 // XFAIL: android
3 //
4 // Different size: detect a bug if detect_odr_violation>=1
5 // RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t-ODR-SO.so
6 // RUN: %clangxx_asan %s %t-ODR-SO.so -Wl,-R. -o %t-ODR-EXE
7 // RUN: ASAN_OPTIONS=detect_odr_violation=1 not %run %t-ODR-EXE 2>&1 | FileCheck %s
8 // RUN: ASAN_OPTIONS=detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s
9 // RUN: ASAN_OPTIONS=detect_odr_violation=0 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
10 // RUN: not %run %t-ODR-EXE 2>&1 | FileCheck %s
12 // Same size: report a bug only if detect_odr_violation>=2.
13 // RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t-ODR-SO.so -DSZ=100
14 // RUN: ASAN_OPTIONS=detect_odr_violation=1 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
15 // RUN: ASAN_OPTIONS=detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s
16 // RUN: not %run %t-ODR-EXE 2>&1 | FileCheck %s
18 // GNU driver doesn't handle .so files properly.
19 // REQUIRES: Clang
21 #ifndef SZ
22 # define SZ 4
23 #endif
25 #if BUILD_SO
26 namespace foo { char G[SZ]; }
27 #else
28 #include <stdio.h>
29 namespace foo { char G[100]; }
30 // CHECK: ERROR: AddressSanitizer: odr-violation
31 // CHECK: size=100 'foo::G' {{.*}}odr-violation.cc:[[@LINE-2]]:22
32 // CHECK: size={{4|100}} 'foo::G'
33 int main(int argc, char **argv) {
34 printf("PASS: %p\n", &foo::G);
36 #endif
38 // CHECK: These globals were registered at these points:
39 // CHECK: ODR-EXE
40 // CHECK: ODR-SO
41 // CHECK: SUMMARY: AddressSanitizer: odr-violation: global 'foo::G' at {{.*}}odr-violation.cc
42 // DISABLED: PASS