We happen to create such ranges today depending on teh scheduling of the
DBG_VALUE instructions. An empty range is not only useless, it can also
be a real issue if it happens to span the 0-0 address range (address ranges
in loaction lists are function relative). 0-0 is defined as the end of
location list marker, thus if such a range is generated it will hide the
other entries of the list. A Dwarf consumer like llvm-dwarfdump that
tries to read the .debug_loc section linearly will get totally lost (this
way of reading .debug_loc could arguably be considered a llvm-dwarfdump
bug though).
Note that the patch as-is replaces a std::pair by a struct containing 'first'
and 'second' members. I did this to expose only the logic changes in this
patch. I can do proper renaming as a first step if we agree on the patch's
direction.
Note also that the patch doesn't contain a real test for the empty range
deletion. It might be tricky to come up with something, but I can try if
we agree that the patch DTRT. The testing part of this patch is the fixup
of 2 tests that happened to pass by mistake as the variables they were
testing referred to invalid empty location lists. Once these ranges gone,
the variable is gone too. I XFAILed one test that wouldn't test anything
if modified and I removed the failing parts of the other one (turns out it
was already failing on linux targets).
Do we need one of these on every InstrRange? I suppose this comes up if we have multiple open InstrRanges at the same time? Do we support/implement that scenario? (I imagine we probably don't - in which case we only need "NonEmpty" for the currently open InstrRange - so perhaps InstrRanges should be a struct of SmallVector<InstrRange> + bool *NonEmpty, so we just have it once per InstrRanges, rather than once for every range within the InstrRanges)