This is an archive of the discontinued LLVM Phabricator instance.

[coverage] Make smaller regions for the first case of a switch.
ClosedPublic

Authored by efriedma on Jun 28 2017, 7:49 PM.

Details

Summary

We never overwrite the end location of region, so we would end up with
an overly large region when we reused the switch's region.

Diff Detail

Repository
rL LLVM

Event Timeline

efriedma created this revision.Jun 28 2017, 7:49 PM
efriedma added a subscriber: cfe-commits.
vsk accepted this revision.Jun 29 2017, 11:15 AM

Thanks for the patch! LGTM.

lib/CodeGen/CoverageMappingGen.cpp
686 ↗(On Diff #104581)

As should return/continue.

This revision is now accepted and ready to land.Jun 29 2017, 11:15 AM
vsk added a comment.Jul 26 2017, 3:08 PM

Hi Eli, are you waiting on something before landing this?

I'm going to look over the overall algorithm one more time to make sure this direction makes sense. The current code for ending regions on break/continue/return/noreturn doesn't really work well, and the way we handle multiple consecutive case statments isn't really right, and I want to make sure I'm not going to end up reverting this. And I need to run some tests to make sure I'm not introducing any crashes. If nothing is wrong, I'll commit tomorrow.

vsk added a comment.Aug 1 2017, 5:53 PM

I'm going to look over the overall algorithm one more time to make sure this direction makes sense. The current code for ending regions on break/continue/return/noreturn doesn't really work well,

Maybe it's worth taking a step back and finding a way to fix that. As you alluded to with the FIXME, there are still some basic cases the current patch won't address:

switch (x) {
  case 1: // Region set to end at the end of the second break.
  case 2:
    break;
  case 3:
  case 4:
    break;
}

and the way we handle multiple consecutive case statments isn't really right,

I agree. It'd be worth seeing whether we can avoid pushing a new region for a case if we know fallthrough occurs.

and I want to make sure I'm not going to end up reverting this. And I need to run some tests to make sure I'm not introducing any crashes. If nothing is wrong, I'll commit tomorrow.

I suspect that fixing switch/cases in a more general way would require reverting this and I know I'll revisit this in the coming weeks. Still, this is an improvement and if nothing goes wrong during testing your plan sgtm.

This revision was automatically updated to reflect the committed changes.