[DebugInfo] Correction for an assert in DIExpression::createFragmentExpression

Summary:
When we create a fragment expression, and there already is an
old fragment expression, we assert that the new fragment is
within the range for the old fragment.

If for example the old fragment expression says that we
describe bit 10-16 of a variable (Offset=10, Size=6),
and we now want to create a new fragment expression only
describing bit 3-6 of the original value, then the resulting
fragment expression should have Offset=13, Size=3.

The assert is supposed to catch if the resulting fragment
expression is outside the range for the old fragment. However,
it used to verify that the Offset+Size of the new fragment was
smaller or equal than Offset+Size for the old fragment. What
we really want to check is that Offset+Size of the new fragment
is smaller than the Size of the old fragment.

Reviewers: aprantl, vsk

Reviewed By: aprantl

Subscribers: davide, llvm-commits, JDevlieghere

Differential Revision: https://reviews.llvm.org/D46391

llvm-svn: 331465
This commit is contained in:
Bjorn Pettersson 2018-05-03 17:04:21 +00:00
parent 304877e5ec
commit 5479ad2945
1 changed files with 3 additions and 3 deletions

View File

@ -830,9 +830,9 @@ Optional<DIExpression *> DIExpression::createFragmentExpression(
case dwarf::DW_OP_LLVM_fragment: {
// Make the new offset point into the existing fragment.
uint64_t FragmentOffsetInBits = Op.getArg(0);
// Op.getArg(0) is FragmentOffsetInBits.
// Op.getArg(1) is FragmentSizeInBits.
assert((OffsetInBits + SizeInBits <= Op.getArg(0) + Op.getArg(1)) &&
uint64_t FragmentSizeInBits = Op.getArg(1);
(void)FragmentSizeInBits;
assert((OffsetInBits + SizeInBits <= FragmentSizeInBits) &&
"new fragment outside of original fragment");
OffsetInBits += FragmentOffsetInBits;
continue;