[llvm-bugs] [Bug 33166] New: Complex DWARF expressions is broken

via llvm-bugs llvm-bugs at lists.llvm.org
Thu May 25 05:07:29 PDT 2017


https://bugs.llvm.org/show_bug.cgi?id=33166

            Bug ID: 33166
           Summary: Complex DWARF expressions is broken
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: DebugInfo
          Assignee: unassignedbugs at nondot.org
          Reporter: amjad.aboud at intel.com
                CC: llvm-bugs at lists.llvm.org

The commit r300522 (PR32382: Fix emitting complex DWARF expressions), broke the
below test:

void bar(int *test);
int foo() {
  int test;

  test = 1;
  bar(&test);

  return test;
}

foo:
       0:       50      pushq   %rax
       1:       c7 44 24 04 01 00 00 00         movl    $1, 4(%rsp)
       9:       48 8d 7c 24 04  leaq    4(%rsp), %rdi
       e:       e8 00 00 00 00  callq   0 <foo+0x13>
      13:       8b 44 24 04     movl    4(%rsp), %eax
      17:       59      popq    %rcx
      18:       c3      retq

Before the commit:
------------------
define i32 @foo() local_unnamed_addr #0 !dbg !5 {
entry:
  %test = alloca i32, align 4
  %0 = bitcast i32* %test to i8*, !dbg !12
  call void @llvm.lifetime.start(i64 4, i8* nonnull %0) #4, !dbg !12
  tail call void @llvm.dbg.value(metadata i32 1, i64 0, metadata !11, metadata
!13), !dbg !12
  store i32 1, i32* %test, align 4, !dbg !14, !tbaa !15
  tail call void @llvm.dbg.value(metadata i32* %test, i64 0, metadata !11,
metadata !19), !dbg !12 ;; <--- This line was changed
  call void @bar(i32* nonnull %test) #4, !dbg !20
  %1 = load i32, i32* %test, align 4, !dbg !21, !tbaa !15
  call void @llvm.dbg.value(metadata i32 %1, i64 0, metadata !11, metadata
!13), !dbg !12
  call void @llvm.lifetime.end(i64 4, i8* nonnull %0) #4, !dbg !22
  ret i32 %1, !dbg !21
}

!11 = !DILocalVariable(name: "test", scope: !5, file: !6, line: 3, type: !9)
!12 = !DILocation(line: 3, scope: !5)
!13 = !DIExpression()
!19 = !DIExpression(DW_OP_deref)

Contents of the .debug_loc section:

    Offset   Begin    End      Expression
    00000000 0000000000000001 000000000000000e (DW_OP_consts: 1;
DW_OP_stack_value)
    00000000 000000000000000e 0000000000000013 (DW_OP_breg7 (rsp): 4)
    00000000 0000000000000017 0000000000000019 (DW_OP_reg0 (rax); DW_OP_piece:
4)
    00000000 <End of list>

After the commit:
-----------------
define i32 @foo() local_unnamed_addr #0 !dbg !5 {
  %test = alloca i32, align 4
  %1 = bitcast i32* %test to i8*, !dbg !12
  call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %1) #4, !dbg !12
  tail call void @llvm.dbg.value(metadata i32 1, i64 0, metadata !11, metadata
!13), !dbg !12
  store i32 1, i32* %test, align 4, !dbg !14, !tbaa !15
  tail call void @llvm.dbg.value(metadata i32* %test, i64 0, metadata !11,
metadata !13), !dbg !12 ;; <--- This line was changed
  call void @bar(i32* nonnull %test) #4, !dbg !19
  %2 = load i32, i32* %test, align 4, !dbg !20, !tbaa !15
  call void @llvm.dbg.value(metadata i32 %2, i64 0, metadata !11, metadata
!13), !dbg !12
  call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull %1) #4, !dbg !21
  ret i32 %2, !dbg !20
}

!11 = !DILocalVariable(name: "test", scope: !5, file: !6, line: 3, type: !9)
!12 = !DILocation(line: 3, scope: !5)
!13 = !DIExpression()

Contents of the .debug_loc section:

    Offset   Begin    End      Expression
    00000000 0000000000000001 000000000000000e (DW_OP_consts: 1;
DW_OP_stack_value)
    00000000 000000000000000e 0000000000000013 (DW_OP_reg5 (rdi))  <-- rdi
contains address of "test".
    00000000 0000000000000017 0000000000000019 (DW_OP_reg0 (rax))
    00000000 <End of list>



The root cause is this change:
===================================================================
--- llvm/lib/Transforms/Utils/Local.cpp   (revision 300521)
+++ llvm/lib/Transforms/Utils/Local.cpp (revision 300522)
@@ -1227,13 +1227,9 @@
           // This is a call by-value or some other instruction that
           // takes a pointer to the variable. Insert a *value*
           // intrinsic that describes the alloca.
-          SmallVector<uint64_t, 1> NewDIExpr;
-          auto *DIExpr = DDI->getExpression();
-          NewDIExpr.push_back(dwarf::DW_OP_deref);
-          NewDIExpr.append(DIExpr->elements_begin(), DIExpr->elements_end());
           DIB.insertDbgValueIntrinsic(AI, 0, DDI->getVariable(),
-                                      DIB.createExpression(NewDIExpr),
-                                      DDI->getDebugLoc(), CI);
+                                      DDI->getExpression(),
DDI->getDebugLoc(),
+                                      CI);
         }
       }
       DDI->eraseFromParent();

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170525/6c319831/attachment.html>


More information about the llvm-bugs mailing list