1 // Test coverage_order_pcs=1 flag which orders the PCs by their appearance.
2 // RUN: DIR=%T/coverage-order-pcs
3 // RUN: rm -rf $DIR
4 // RUN: mkdir $DIR
5 // RUN: %clangxx_asan -fsanitize-coverage=func %s -o %t
6 // RUN: %env_asan_opts=coverage_dir=$DIR:coverage=1:coverage_order_pcs=0 %run %t
7 // RUN: mv $DIR/*sancov $DIR/A
8 
9 // RUN: %env_asan_opts=coverage_dir=$DIR:coverage=1:coverage_order_pcs=0 %run %t 1
10 // RUN: mv $DIR/*sancov $DIR/B
11 
12 // RUN: %env_asan_opts=coverage_dir=$DIR:coverage=1:coverage_order_pcs=1 %run %t
13 // RUN: mv $DIR/*sancov $DIR/C
14 
15 // RUN: %env_asan_opts=coverage_dir=$DIR:coverage=1:coverage_order_pcs=1 %run %t 1
16 // RUN: mv $DIR/*sancov $DIR/D
17 //
18 // RUN: (%sancov print $DIR/A; %sancov print $DIR/B; %sancov print $DIR/C; %sancov print $DIR/D) | FileCheck %s
19 //
20 // RUN: rm -rf $DIR
21 // Ordering works only in 64-bit mode for now.
22 // REQUIRES: asan-64-bits
23 // UNSUPPORTED: android
24 #include <stdio.h>
25 
foo()26 void foo() { fprintf(stderr, "FOO\n"); }
bar()27 void bar() { fprintf(stderr, "BAR\n"); }
28 
main(int argc,char ** argv)29 int main(int argc, char **argv) {
30   if (argc == 2) {
31     foo();
32     bar();
33   } else {
34     bar();
35     foo();
36   }
37 }
38 
39 // Run A: no ordering
40 // CHECK: [[FOO:0x[0-9a-f]*]]
41 // CHECK-NEXT: [[BAR:0x[0-9a-f]*]]
42 // CHECK-NEXT: [[MAIN:0x[0-9a-f]*]]
43 //
44 // Run B: still no ordering
45 // CHECK-NEXT: [[FOO]]
46 // CHECK-NEXT: [[BAR]]
47 // CHECK-NEXT: [[MAIN]]
48 //
49 // Run C: MAIN, BAR, FOO
50 // CHECK-NEXT: [[MAIN]]
51 // CHECK-NEXT: [[BAR]]
52 // CHECK-NEXT: [[FOO]]
53 //
54 // Run D: MAIN, FOO, BAR
55 // CHECK-NEXT: [[MAIN]]
56 // CHECK-NEXT: [[FOO]]
57 // CHECK-NEXT: [[BAR]]
58