| 1 | // XFAIL: * |
| 2 | //// Suboptimal coverage, see below. |
| 3 | |
| 4 | // REQUIRES: lldb |
| 5 | // UNSUPPORTED: system-windows |
| 6 | // RUN: %clang -std=gnu11 -O3 -glldb %s -o %t |
| 7 | // RUN: %dexter --fail-lt 1.0 -w --debugger lldb --binary %t -- %s |
| 8 | |
| 9 | //// Check that escaped local 'param' in function 'fun' has sensible debug info |
| 10 | //// after the escaping function 'use' gets arg promotion (int* -> int). Currently |
| 11 | //// we lose track of param after the loop header. |
| 12 | |
| 13 | int g = 0; |
| 14 | //// A no-inline, read-only function with internal linkage is a good candidate |
| 15 | //// for arg promotion. |
| 16 | __attribute__((__noinline__)) |
| 17 | static void use(const int* p) { |
| 18 | //// Promoted args would be a good candidate for an DW_OP_implicit_pointer. |
| 19 | //// This desirable behaviour is checked for in the test implicit-ptr.c. |
| 20 | g = *p; |
| 21 | } |
| 22 | |
| 23 | __attribute__((__noinline__)) |
| 24 | void do_thing(int x) { |
| 25 | g *= x; |
| 26 | } |
| 27 | |
| 28 | __attribute__((__noinline__)) |
| 29 | int fun(int param) { |
| 30 | do_thing(x: 0); // DexLabel('s2') |
| 31 | for (int i = 0; i < param; ++i) { |
| 32 | use(p: ¶m); |
| 33 | } |
| 34 | |
| 35 | //// x86 loop body looks like this, with param in ebx: |
| 36 | //// 4004b0: mov edi,ebx |
| 37 | //// 4004b2: call 4004d0 <_ZL3usePKi> |
| 38 | //// 4004b7: add ebp,0xffffffff |
| 39 | //// 4004ba: jne 4004b0 <_Z3funi+0x20> |
| 40 | |
| 41 | //// But we lose track of param's location before the loop: |
| 42 | //// DW_TAG_formal_parameter |
| 43 | //// DW_AT_location (0x00000039: |
| 44 | //// [0x0000000000400490, 0x0000000000400495): DW_OP_reg5 RDI |
| 45 | //// [0x0000000000400495, 0x00000000004004a2): DW_OP_reg3 RBX) |
| 46 | //// DW_AT_name ("param") |
| 47 | |
| 48 | return g; // DexLabel('s3') |
| 49 | } |
| 50 | |
| 51 | int main() { |
| 52 | return fun(param: 5); |
| 53 | } |
| 54 | |
| 55 | // DexExpectWatchValue('*p', 5, 5, 5, 5, 5, on_line=ref('s1')) |
| 56 | // DexExpectWatchValue('param', 5, from_line=ref('s2'), to_line=ref('s3')) |
| 57 | |