llvm-dwarfdump --statistics can miscalculate scope bytes covered
| 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,
Fixed in 3ff4d75c9cb (D85636).
Review for possible fix here https://reviews.llvm.org/D85636