1 // RUN: %clang_cc1 -triple %itanium_abi_triple %s -o - -emit-llvm -fprofile-instrument=clang -fcoverage-mapping -fcoverage-mcdc | FileCheck %s -check-prefix=MCDC
2 // RUN: %clang_cc1 -triple %itanium_abi_triple %s -o - -emit-llvm -fprofile-instrument=clang -fcoverage-mapping | FileCheck %s -check-prefix=NOMCDC
4 int test(int b
, int c
, int d
, int e
, int f
) {
5 return ((b
? c
: d
) && e
&& f
);
8 // NOMCDC-NOT: %mcdc.addr
9 // NOMCDC-NOT: __profbm_test
12 // MCDC: @__profbm_test = private global [1 x i8] zeroinitializer
14 // ALLOCATE MCDC TEMP AND ZERO IT.
16 // MCDC: %mcdc.addr = alloca i32, align 4
17 // MCDC: store i32 0, ptr %mcdc.addr, align 4
19 // TERNARY TRUE SHOULD SHIFT ID = 0 FOR CONDITION 'c'.
20 // MCDC-LABEL: cond.true:
21 // MCDC: %[[LAB1:[0-9]+]] = load i32, ptr %c.addr, align 4
22 // MCDC-DAG: %[[BOOL:tobool[0-9]*]] = icmp ne i32 %[[LAB1]], 0
23 // MCDC-DAG: %[[TEMP:mcdc.*]] = load i32, ptr %mcdc.addr, align 4
24 // MCDC-DAG: %[[LAB2:[0-9]+]] = add i32 %[[TEMP]], 0
25 // MCDC-DAG: %[[LAB3:[0-9]+]] = add i32 %[[TEMP]], 0
26 // MCDC-DAG: %[[LAB4:[0-9]+]] = select i1 %[[BOOL]], i32 %[[LAB2]], i32 %[[LAB3]]
27 // MCDC-DAG: store i32 %[[LAB4]], ptr %mcdc.addr, align 4
29 // TERNARY FALSE SHOULD SHIFT ID = 0 FOR CONDITION 'd'.
30 // MCDC-LABEL: cond.false:
31 // MCDC: %[[LAB1:[0-9]+]] = load i32, ptr %d.addr, align 4
32 // MCDC-DAG: %[[BOOL:tobool[0-9]*]] = icmp ne i32 %[[LAB1]], 0
33 // MCDC-DAG: %[[TEMP:mcdc.*]] = load i32, ptr %mcdc.addr, align 4
34 // MCDC-DAG: %[[LAB2:[0-9]+]] = add i32 %[[TEMP]], 0
35 // MCDC-DAG: %[[LAB3:[0-9]+]] = add i32 %[[TEMP]], 0
36 // MCDC-DAG: %[[LAB4:[0-9]+]] = select i1 %[[BOOL]], i32 %[[LAB2]], i32 %[[LAB3]]
37 // MCDC-DAG: store i32 %[[LAB4]], ptr %mcdc.addr, align 4
39 // SHIFT SECOND CONDITION WITH ID = 2.
40 // MCDC: %[[LAB1:[0-9]+]] = load i32, ptr %e.addr, align 4
41 // MCDC-DAG: %[[BOOL:tobool[0-9]*]] = icmp ne i32 %[[LAB1]], 0
42 // MCDC-DAG: %[[TEMP:mcdc.*]] = load i32, ptr %mcdc.addr, align 4
43 // MCDC-DAG: %[[LAB2:[0-9]+]] = add i32 %[[TEMP]], 0
44 // MCDC-DAG: %[[LAB3:[0-9]+]] = add i32 %[[TEMP]], 1
45 // MCDC-DAG: %[[LAB4:[0-9]+]] = select i1 %[[BOOL]], i32 %[[LAB2]], i32 %[[LAB3]]
46 // MCDC-DAG: store i32 %[[LAB4]], ptr %mcdc.addr, align 4
48 // SHIFT THIRD CONDITION WITH ID = 1.
49 // MCDC: %[[LAB1:[0-9]+]] = load i32, ptr %f.addr, align 4
50 // MCDC-DAG: %[[BOOL:tobool[0-9]*]] = icmp ne i32 %[[LAB1]], 0
51 // MCDC-DAG: %[[TEMP:mcdc.*]] = load i32, ptr %mcdc.addr, align 4
52 // MCDC-DAG: %[[LAB2:[0-9]+]] = add i32 %[[TEMP]], 3
53 // MCDC-DAG: %[[LAB3:[0-9]+]] = add i32 %[[TEMP]], 2
54 // MCDC-DAG: %[[LAB4:[0-9]+]] = select i1 %[[BOOL]], i32 %[[LAB2]], i32 %[[LAB3]]
55 // MCDC-DAG: store i32 %[[LAB4]], ptr %mcdc.addr, align 4
57 // UPDATE FINAL BITMASK WITH RESULT.
58 // MCDC-DAG: %[[TEMP0:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4
59 // MCDC: %[[TEMP:[0-9]+]] = add i32 %[[TEMP0]], 0
60 // MCDC: %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3
61 // MCDC: %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr @__profbm_test, i32 %[[LAB1]]
62 // MCDC: %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
63 // MCDC: %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
64 // MCDC: %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]
65 // MCDC: %[[BITS:.+]] = load i8, ptr %[[LAB4]], align 1
66 // MCDC: %[[LAB8:[0-9]+]] = or i8 %[[BITS]], %[[LAB7]]
67 // MCDC: store i8 %[[LAB8]], ptr %[[LAB4]], align 1