This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by bjope on May 3 2018, 7:27 AM.

Details

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.

Diff Detail

Event Timeline

bjope created this revision.May 3 2018, 7:27 AM
davide added a subscriber: davide.May 3 2018, 8:02 AM

Does this fire anywhere? If so, we should try adding a test.

bjope added a comment.May 3 2018, 8:18 AM

Does this fire anywhere? If so, we should try adding a test.

We did hit the assert in PR37321 (but with Op.getArg(0)==0), that problem will be solved in D46384.
The incorrect upper limit for Op.getArg(0)!=0 was more or less spotted by code inspection.

aprantl accepted this revision.May 3 2018, 8:39 AM

So this is making the assertion even stricter. Thanks!

lib/IR/DebugInfoMetadata.cpp
832

Actually this comment is silly, too:

uint64_t FragmentOffsetInBits = Op.getArg(0);
uint64_t FragmentSizeInBits = Op.getArg(1);
(void)FragmentSizeInBits;
assert((OffsetInBits + SizeInBits <= FragmentSizeInBits) && ....);
This revision is now accepted and ready to land.May 3 2018, 8:39 AM
bjope added inline comments.May 3 2018, 9:47 AM
lib/IR/DebugInfoMetadata.cpp
832

Ok, I'll fix that as well. Thanks for the review!

This revision was automatically updated to reflect the committed changes.