llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

llvm-dwarfdump --statistics can miscalculate scope bytes covered

Open OCHyams opened this issue 6 years ago • 2 comments

Bugzilla Link 46575
Resolution FIXED
Resolved on Aug 25, 2020 01:46
Version trunk
OS Linux
Attachments example.ll
CC @JDevlieghere,@jmorse,@walkerkd,@pogo59
Fixed by commit(s) 3ff4d75c9cbffb12c5c690c389e3977ea6811042

Extended Description

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,

OCHyams avatar Jul 03 '20 09:07 OCHyams

Fixed in 3ff4d75c9cb (D85636).

OCHyams avatar Aug 25 '20 08:08 OCHyams

Review for possible fix here https://reviews.llvm.org/D85636

OCHyams avatar Aug 10 '20 11:08 OCHyams