<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 - llvm-dwarfdump --statistics can miscalculate scope bytes covered"
   href="https://bugs.llvm.org/show_bug.cgi?id=46575">46575</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>llvm-dwarfdump --statistics can miscalculate scope bytes covered
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </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>new bugs
          </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>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=23675" name="attach_23675" title="example.ll">attachment 23675</a> <a href="attachment.cgi?id=23675&action=edit" title="example.ll">[details]</a></span>
example.ll

Tools built with trunk f1c671925b1c60ded3e4e7b3c6b1ec984b2d9b93.

For a variable described with a location list, the stat
'sum_all_variables(#bytes in parent scope covered by DW_AT_location)' is
calculated by summing all bytes covered by the location ranges in the list
and capping the result to the number of bytes in the parent scope. No effort is
made to discern whether the bytes covered are 'bytes in parent scope'.

clang seems to produce a fair number of location ranges which cover bytes
outside of the variables scope like this (see D82129).

I've attached an IR file based on the test
llvm/test/DebugInfo/COFF/register-variables.ll which can be compiled with llc
to demonstrate this happening. All dbg.values have been removed except for
variable 'c', so only 'c' has any byte coverage.

$ llc example.ll -filetype=obj -o example.o && llvm-dwarfdump example.o
...
   DW_TAG_lexical_block
     DW_AT_low_pc       (0x0000000000000003)
     DW_AT_high_pc      (0x0000000000000008)

     DW_TAG_variable
       DW_AT_location   (0x00000000: 
          [0x0000000000000014, 0x000000000000001c): DW_OP_reg0 RAX)
       DW_AT_name       ("c")
       DW_AT_decl_file  ("/t.cpp")
       DW_AT_decl_line  (15)
       DW_AT_type       (0x00000044 "int")


Although the DW_AT_location range [0x0000000000000014, 0x000000000000001c)
covers no bytes in the parent scope [0x0000000000000003, 0x0000000000000008),
llvm-dwarfdump reports 5 bytes are covered:

$ llvm-dwarfdump --statistics example.o | python -m json.tool
...
"sum_all_local_vars(#bytes in parent scope covered by DW_AT_location)": 5,


I'd expect to instead see:

"sum_all_local_vars(#bytes in parent scope covered by DW_AT_location)": 0,</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>