1; Test -sanitizer-coverage-trace-compares=1 (instrumenting a switch)
2; RUN: opt < %s -sancov -sanitizer-coverage-level=1 -sanitizer-coverage-trace-compares=1  -S -enable-new-pm=0 | FileCheck %s
3; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=1 -sanitizer-coverage-trace-compares=1  -S | FileCheck %s
4
5target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
6target triple = "x86_64-unknown-linux-gnu"
7declare void @_Z3bari(i32)
8define void @foo(i32 %x) {
9entry:
10; CHECK: __sancov_gen_cov_switch_values = internal global [5 x i64] [i64 3, i64 32, i64 1, i64 101, i64 1001]
11; CHECK: [[TMP:%[0-9]*]] = zext i32 %x to i64
12; CHECK-NEXT: call void @__sanitizer_cov_trace_switch(i64 [[TMP]], i64* getelementptr inbounds ([5 x i64], [5 x i64]* @__sancov_gen_cov_switch_values, i32 0, i32 0))
13  switch i32 %x, label %sw.epilog [
14    i32 1, label %sw.bb
15    i32 1001, label %sw.bb.1
16    i32 101, label %sw.bb.2
17  ]
18
19sw.bb:                                            ; preds = %entry
20  tail call void @_Z3bari(i32 4)
21  br label %sw.epilog
22
23sw.bb.1:                                          ; preds = %entry
24  tail call void @_Z3bari(i32 5)
25  br label %sw.epilog
26
27sw.bb.2:                                          ; preds = %entry
28  tail call void @_Z3bari(i32 6)
29  br label %sw.epilog
30
31sw.epilog:                                        ; preds = %entry, %sw.bb.2, %sw.bb.1, %sw.bb
32  ret void
33}
34
35define void @fooi72(i72 %x) {
36entry:
37  switch i72 %x, label %sw.epilog [
38    i72 1, label %sw.bb
39    i72 101, label %sw.bb.1
40    i72 1001, label %sw.bb.2
41  ]
42
43sw.bb:                                            ; preds = %entry
44  tail call void @_Z3bari(i32 4)
45  br label %sw.epilog
46
47sw.bb.1:                                          ; preds = %entry
48  tail call void @_Z3bari(i32 5)
49  br label %sw.epilog
50
51sw.bb.2:                                          ; preds = %entry
52  tail call void @_Z3bari(i32 6)
53  br label %sw.epilog
54
55sw.epilog:                                        ; preds = %entry, %sw.bb.2, %sw.bb.1, %sw.bb
56  ret void
57}
58