[PATCH] D61600: [DebugInfo] More precise variable range for stack locations

David Stenberg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 7 06:22:29 PDT 2019


dstenb added a reviewer: jmorse.
dstenb added a comment.

(Adding Jeremy as reviewer as he has also been working in this area recently.)



================
Comment at: lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp:375
             unsigned RegNo = DbgValue->getOperand(0).getReg();
-            if (TRI->isVirtualRegister(RegNo) || ChangingRegs.test(RegNo))
+            if (TRI->isVirtualRegister(RegNo) || ChangingRegs.test(RegNo) ||
+                FrameReg == RegNo)
----------------
Perhaps this must not be done in this patch, but I wonder if we should close all register-described values here?

For example:

```
volatile int g;

int baz(int p) {
  int local = 123;

  if (g > 1) {
    local = p;
    g += p;
  }

  return 3;
}
```

when compiling the above with `clang -O1 -g --target=x86_64-unknown-linux-gnu` we land in the following MIR after livedebugvalues:

```
  bb.0.entry:
    successors: %bb.1(0x40000000), %bb.2(0x40000000)
    liveins: $edi
  
    DBG_VALUE $edi, $noreg, !16, !DIExpression(), debug-location !18
    DBG_VALUE $edi, $noreg, !16, !DIExpression(), debug-location !18
    DBG_VALUE 123, $noreg, !17, !DIExpression(), debug-location !19
    renamable $eax = MOV32rm $rip, 1, $noreg, @g, $noreg, debug-location !20 :: (volatile dereferenceable load 4 from @g, !tbaa !22)
    CMP32ri8 killed renamable $eax, 2, implicit-def $eflags, debug-location !26
    JCC_1 %bb.2, 12, implicit $eflags, debug-location !27
  
  bb.1.if.then:
    successors: %bb.2(0x80000000)
    liveins: $edi
  
    DBG_VALUE 123, $noreg, !17, !DIExpression(), debug-location !19
    DBG_VALUE $edi, $noreg, !16, !DIExpression(), debug-location !18
    DBG_VALUE $edi, $noreg, !17, !DIExpression(), debug-location !19
    ADD32mr $rip, 1, $noreg, @g, $noreg, killed renamable $edi, implicit-def dead $eflags, debug-location !28 :: (volatile store 4 into @g, !tbaa !22), (volatile dereferenceable load 4 from @g, !tbaa !22)
  
  bb.2.if.end:
    DBG_VALUE $edi, $noreg, !16, !DIExpression(), debug-location !18
    $eax = MOV32ri 3, debug-location !31
    RETQ $eax, debug-location !31
```

As seen, in the `g > 1` branch the `local` variable is described by edi. As edi is not modified, it will not be contained in `ChangingRegs`.

As we don't close the range here, this means that we'll incorrectly describe `local` using edi for the rest of the function:

```
                  DW_AT_location	(0x00000000
                     [0x0000000000000000,  0x000000000000000b): DW_OP_consts +123, DW_OP_stack_value
                     [0x000000000000000b,  0x0000000000000017): DW_OP_reg5 RDI)
```

```
0000000000000000 baz:
       0: 8b 05 00 00 00 00            	movl	(%rip), %eax
       6: 83 f8 02                     	cmpl	$2, %eax
       9: 7c 06                        	jl	6 <baz+0x11>
       b: 01 3d 00 00 00 00            	addl	%edi, (%rip)
      11: b8 03 00 00 00               	movl	$3, %eax
      16: c3                           	retq
```



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61600/new/

https://reviews.llvm.org/D61600





More information about the llvm-commits mailing list