This is an archive of the discontinued LLVM Phabricator instance.

[ADT] IntervalMap: fix setStart and setStop
ClosedPublic

Authored by mlemay-intel on Oct 27 2016, 9:30 PM.

Details

Summary

These functions currently require that the new closed interval has a length of
at least 2. They also currently permit empty half-open intervals. This patch
defines nonEmpty in each traits structure and uses it to correct the
implementations of setStart and setStop.

Diff Detail

Repository
rL LLVM

Event Timeline

mlemay-intel retitled this revision from to [ADT] IntervalMap: fix setStart and setStop.
mlemay-intel updated this object.
mlemay-intel added reviewers: stoklund, chandlerc.
mlemay-intel added a subscriber: llvm-commits.
vsk added a subscriber: vsk.Oct 27 2016, 10:13 PM

Could you add unit tests to unittest/ADT/IntervalMapTest? I want to make sure that:

  • We're allowed to create 1-element intervals using setStart/setStop.
  • If we create a 0-element interval using setStart/setStop, it just gets deleted.
In D26064#581794, @vsk wrote:

...

  • If we create a 0-element interval using setStart/setStop, it just gets deleted.

The revised assertion will fail in that case. Is deleting the interval actually the desired behavior?

vsk added a comment.Oct 28 2016, 10:59 AM
In D26064#581794, @vsk wrote:

...

  • If we create a 0-element interval using setStart/setStop, it just gets deleted.

The revised assertion will fail in that case. Is deleting the interval actually the desired behavior?

Looking at it more, it shouldn't be possible to do what I described (creating a 0-element interval using setStart/setStop). I'm walking the request for that test back :).

In D26064#582202, @vsk wrote:
In D26064#581794, @vsk wrote:

...

  • If we create a 0-element interval using setStart/setStop, it just gets deleted.

The revised assertion will fail in that case. Is deleting the interval actually the desired behavior?

Looking at it more, it shouldn't be possible to do what I described (creating a 0-element interval using setStart/setStop). I'm walking the request for that test back :).

Sounds good, thanks. :)

Added unit tests.

vsk accepted this revision.Oct 28 2016, 5:47 PM
vsk added a reviewer: vsk.

LGTM. Could you wait a day or two before committing? I haven't worked on IntervalMap before, so it'd be nice to others a chance to chime in.

unittests/ADT/IntervalMapTest.cpp
19 ↗(On Diff #76273)

nit: You don't need the extra space, 'IntervalMapHalfOpenInfo<unsigned>>' would be fine.

This revision is now accepted and ready to land.Oct 28 2016, 5:47 PM
In D26064#582725, @vsk wrote:

LGTM. Could you wait a day or two before committing? I haven't worked on IntervalMap before, so it'd be nice to others a chance to chime in.

Sure, I'll wait a couple of days. Thanks!

mlemay-intel edited edge metadata.

Eliminated unnecessary space in template instantiation.
Revised test for half-open intervals to cover using setStop to create an interval with a length of 1.

This revision was automatically updated to reflect the committed changes.