1// RUN: %clang++ -std=gnu++11 -O2 -g %s -o %t
2// RUN: %dexter --fail-lt 1.0 -w \
3// RUN: --binary %t --debugger 'lldb' -- %s
4// RUN: %clang++ -std=gnu++11 -O0 -g %s -o %t
5// RUN: %dexter --fail-lt 1.0 -w \
6// RUN: --binary %t --debugger 'lldb' -- %s
7
8// REQUIRES: lldb, D136396
9// Currently getting intermittent failures on darwin.
10// UNSUPPORTED: system-windows, system-darwin
11
12//// Check that the debugging experience with __attribute__((optnone)) at O2
13//// matches O0. Test simple functions performing simple arithmetic
14//// operations and small loops.
15
16__attribute__((optnone))
17int test1(int test1_a, int test1_b) {
18 int test1_result = 0;
19 // DexLabel('test1_start')
20 test1_result = test1_a + test1_b; // DexExpectStepOrder(1)
21 return test1_result; // DexExpectStepOrder(2)
22 // DexLabel('test1_end')
23}
24// DexExpectWatchValue('test1_a', 3, from_line=ref('test1_start'), to_line=ref('test1_end'))
25// DexExpectWatchValue('test1_b', 4, from_line=ref('test1_start'), to_line=ref('test1_end'))
26// DexExpectWatchValue('test1_result', 0, 7, from_line=ref('test1_start'), to_line=ref('test1_end'))
27
28__attribute__((optnone))
29int test2(int test2_a, int test2_b) {
30 int test2_result = test2_a + test2_a + test2_a + test2_a; // DexExpectStepOrder(3)
31 // DexLabel('test2_start')
32 return test2_a << 2; // DexExpectStepOrder(4)
33 // DexLabel('test2_end')
34}
35// DexExpectWatchValue('test2_a', 1, from_line=ref('test2_start'), to_line=ref('test2_end'))
36// DexExpectWatchValue('test2_b', 2, from_line=ref('test2_start'), to_line=ref('test2_end'))
37// DexExpectWatchValue('test2_result', 4, from_line=ref('test2_start'), to_line=ref('test2_end'))
38
39__attribute__((optnone))
40int test3(int test3_a, int test3_b) {
41 int test3_temp1 = 0, test3_temp2 = 0;
42 // DexLabel('test3_start')
43 test3_temp1 = test3_a + 5; // DexExpectStepOrder(5)
44 test3_temp2 = test3_b + 5; // DexExpectStepOrder(6)
45 if (test3_temp1 > test3_temp2) { // DexExpectStepOrder(7)
46 test3_temp1 *= test3_temp2; // DexUnreachable()
47 }
48 return test3_temp1; // DexExpectStepOrder(8)
49 // DexLabel('test3_end')
50}
51// DexExpectWatchValue('test3_a', 5, from_line=ref('test3_start'), to_line=ref('test3_end'))
52// DexExpectWatchValue('test3_b', 6, from_line=ref('test3_start'), to_line=ref('test3_end'))
53// DexExpectWatchValue('test3_temp1', 0, 10, from_line=ref('test3_start'), to_line=ref('test3_end'))
54// DexExpectWatchValue('test3_temp2', 0, 11, from_line=ref('test3_start'), to_line=ref('test3_end'))
55
56unsigned num_iterations = 4;
57
58__attribute__((optnone))
59int test4(int test4_a, int test4_b) {
60 int val1 = 0, val2 = 0;
61 // DexLabel('test4_start')
62
63 val1 = (test4_a > test4_b) ? test4_a : test4_b; // DexExpectStepOrder(9)
64 val2 = val1;
65 val2 += val1; // DexExpectStepOrder(10)
66
67 for (unsigned i=0; i != num_iterations; ++i) { // DexExpectStepOrder(11, 13, 15, 17, 19)
68 val1--;
69 val2 += i;
70 if (val2 % 2 == 0) // DexExpectStepOrder(12, 14, 16, 18)
71 val2 /= 2;
72 }
73
74 return (val1 > val2) ? val2 : val1; // DexExpectStepOrder(20)
75 // DexLabel('test4_end')
76}
77// DexExpectWatchValue('test4_a', 1, from_line=ref('test4_start'), to_line=ref('test4_end'))
78// DexExpectWatchValue('test4_b', 9, from_line=ref('test4_start'), to_line=ref('test4_end'))
79// DexExpectWatchValue('val1', 0, 9, 8, 7, 6, 5, from_line=ref('test4_start'), to_line=ref('test4_end'))
80// DexExpectWatchValue('val2', 0, 9, 18, 9, 10, 5, 7, 10, 5, 9, from_line=ref('test4_start'), to_line=ref('test4_end'))
81
82__attribute__((optnone))
83int test5(int test5_val) {
84 int c = 1; // DexExpectStepOrder(21)
85 // DexLabel('test5_start')
86 if (test5_val) // DexExpectStepOrder(22)
87 c = 5; // DexExpectStepOrder(23)
88 return c ? test5_val : test5_val; // DexExpectStepOrder(24)
89 // DexLabel('test5_end')
90}
91// DexExpectWatchValue('test5_val', 7, from_line=ref('test5_start'), to_line=ref('test5_end'))
92// DexExpectWatchValue('c', 1, 5, from_line=ref('test5_start'), to_line=ref('test5_end'))
93
94__attribute__((optnone))
95int main() {
96 int main_result = 0;
97 // DexLabel('main_start')
98 main_result = test1(test1_a: 3,test1_b: 4);
99 main_result += test2(test2_a: 1,test2_b: 2);
100 main_result += test3(test3_a: 5,test3_b: 6);
101 main_result += test4(test4_a: 1,test4_b: 9);
102 main_result += test5(test5_val: 7);
103 return main_result;
104 // DexLabel('main_end')
105}
106// DexExpectWatchValue('main_result', 0, 7, 11, 21, 26, 33, from_line=ref('main_start'), to_line=ref('main_end'))
107

source code of cross-project-tests/debuginfo-tests/dexter-tests/optnone-simple-functions.cpp