1 // XFAIL:*
2 //// Suboptimal coverage, see inlined comments.
3 
4 // REQUIRES: lldb
5 // UNSUPPORTED: system-windows
6 // RUN: %dexter --fail-lt 1.0 -w --debugger lldb \
7 // RUN:     --builder 'clang-c' --cflags "-O3 -glldb" -- %s
8 
9 //// Adapted from https://bugs.llvm.org/show_bug.cgi?id=34136#c4
10 
11 int g;
12 
13 __attribute__((__noinline__))
esc(int * p)14 void esc(int* p) {
15   g = *p;
16   *p = 5;
17 }
18 
19 __attribute__((__noinline__))
thing(int x)20 void thing(int x) {
21   g = x;
22 }
23 
24 __attribute__((__noinline__))
fun(int param)25 int fun(int param) {
26   esc(&param);      //// alloca is live until here        DexLabel('s1')
27   if (param == 0) { //// end of alloca live range
28     //// param is now a constant, but without lowering to dbg.value we can't
29     //// capture that and would still point to the stack slot that may even have
30     //// been reused by now.
31     ////
32     //// Right now we get suboptimal coverage for x86: the param load below is
33     //// CSE'd with the if condition.
34     //// Instcombine runs LowerDbgDeclare and inserts a dbg.value after the load.
35     //// SelectionDAG combines the load and cmp. We go from this IR:
36     ////   %0 = load i32, i32* %param.addr, align 4, !dbg !42, !tbaa !20
37     ////   call void @llvm.dbg.value(metadata i32 %0, ...
38     ////   %cmp = icmp eq i32 %0, 0, !dbg !44
39     //// to this MIR:
40     ////   DBG_VALUE $noreg, $noreg, !"param"...
41     ////   CMP32mi8 %param.addr, 1, $noreg, 0, $noreg, 0, implicit-def $eflags, debug-location !44
42     thing(param);
43   }
44   return 0; //                                            DexLabel('s2')
45 }
46 
main()47 int main() {
48   return fun(5);
49 }
50 
51 // DexExpectWatchValue('param', '5',  from_line='s1', to_line='s2')
52 
53