1 // RUN: %clangxx_asan -mllvm -asan-coverage=1 -DSHARED %s -shared -o %t.so -fPIC
2 // RUN: %clangxx_asan -mllvm -asan-coverage=1 %s -o %t -Wl,-R. %t.so
3 // RUN: export ASAN_OPTIONS=coverage=1:verbosity=1
4 // RUN: %t 2>&1 | FileCheck %s --check-prefix=CHECK-main
5 // RUN: %t foo 2>&1 | FileCheck %s --check-prefix=CHECK-foo
6 // RUN: %t bar 2>&1 | FileCheck %s --check-prefix=CHECK-bar
7 // RUN: %t foo bar 2>&1 | FileCheck %s --check-prefix=CHECK-foo-bar
8 // RUN: not %t foo bar 1 2 2>&1 | FileCheck %s --check-prefix=CHECK-report
10 // https://code.google.com/p/address-sanitizer/issues/detail?id=263
18 void bar() { printf("bar\n"); }
20 __attribute__((noinline
))
21 void foo() { printf("foo\n"); }
26 int main(int argc
, char **argv
) {
27 fprintf(stderr
, "PID: %d\n", getpid());
28 for (int i
= 1; i
< argc
; i
++) {
29 if (!strcmp(argv
[i
], "foo"))
31 if (!strcmp(argv
[i
], "bar"))
34 return G
[argc
]; // Buffer overflow if argc >= 4.
38 // CHECK-main: PID: [[PID:[0-9]+]]
39 // CHECK-main: [[PID]].sancov: 1 PCs written
40 // CHECK-main-NOT: .so.[[PID]]
42 // CHECK-foo: PID: [[PID:[0-9]+]]
43 // CHECK-foo: [[PID]].sancov: 2 PCs written
44 // CHECK-foo-NOT: .so.[[PID]]
46 // CHECK-bar: PID: [[PID:[0-9]+]]
47 // CHECK-bar: [[PID]].sancov: 1 PCs written
48 // CHECK-bar: .so.[[PID]].sancov: 1 PCs written
50 // CHECK-foo-bar: PID: [[PID:[0-9]+]]
51 // CHECK-foo-bar: [[PID]].sancov: 2 PCs written
52 // CHECK-foo-bar: so.[[PID]].sancov: 1 PCs written
54 // CHECK-report: AddressSanitizer: global-buffer-overflow
55 // CHECK-report: PCs written