<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Complex DWARF expressions is broken"
   href="https://bugs.llvm.org/show_bug.cgi?id=33166">33166</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Complex DWARF expressions is broken
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>DebugInfo
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>amjad.aboud@intel.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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();</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>