<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 - [DebugInfo] Bloated dwarf for single location variable in nested scope"
   href="https://bugs.llvm.org/show_bug.cgi?id=45889">45889</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[DebugInfo] Bloated dwarf for single location variable in nested scope
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Common Code Generator Code
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>orlando.hyams@sony.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=23476" name="attach_23476" title="XFAIL llvm-lit test">attachment 23476</a> <a href="attachment.cgi?id=23476&action=edit" title="XFAIL llvm-lit test">[details]</a></span>
XFAIL llvm-lit test

We get bloated dwarf for a variable location in a nested scope if it also has a
location tracked outside of that scope. I've attached a test case which fails
with llvm built at 72edb7986a8 (12th May 2020).

$ llc -start-after=livedebugvalues --filetype=obj test.mir -o - |
llvm-dwarfdump -
...
DW_TAG_lexical_block
  DW_AT_low_pc  (0x0000000000000002)
  DW_AT_high_pc (0x0000000000000003)

  DW_TAG_variable
    DW_AT_location    (0x00000000: 
       [0x0000000000000000, 0x0000000000000002): DW_OP_reg5 RDI
       [0x0000000000000002, 0x0000000000000003): DW_OP_reg0 RAX)
    DW_AT_name  ("local")
...

Despite the fact that we have a location (DW_OP_reg0 RAX) which covers the
entire lexical block [0x0000000000000002, 0x0000000000000003) in which the
variable lives, we emit a location list. I think we could emit this instead:

DW_TAG_lexical_block
  DW_AT_low_pc  (0x0000000000000002)
  DW_AT_high_pc (0x0000000000000003)

  DW_TAG_variable
    DW_AT_location   (DW_OP_reg0 RAX)
    DW_AT_name       ("local")</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>