This is an archive of the discontinued LLVM Phabricator instance.

[Coverage] Fix crash in VisitIfStmt
ClosedPublic

Authored by vsk on Feb 5 2016, 2:23 PM.

Details

Summary

When handling 'if' statements, we crash if the condition and the consequent
branch are spanned by a single macro expansion.

The crash occurs because of a sanity 'reset' in popRegions(): if an expansion
exactly spans an entire region, we set MostRecentLocation to the start of the
expansion (its 'include location'). This ensures we don't handleFileExit()
ourselves out of the expansion before we're done processing all of the regions
within it. This is tested in test/CoverageMapping/macro-expressions.c.

This causes a problem when an expansion spans both the condition and the
consequent branch of an 'if' statement. MostRecentLocation is updated to the
start of the 'if' statement in popRegions(), so the file for the expansion
isn't exited by the time we're done handling the statement. We then crash with
'fatal: File exit not handled before popRegions'.

The fix for this is to detect these kinds of expansions, and conservatively
update MostRecentLocation to the end of expansion region containing the
conditional. I've added tests to make sure we don't have the same problem with
other kinds of statements.

rdar://problem/23630316

Diff Detail

Event Timeline

vsk updated this revision to Diff 47048.Feb 5 2016, 2:23 PM
vsk retitled this revision from to [Coverage] Fix crash in VisitIfStmt.
vsk updated this object.
vsk added a reviewer: bogner.
vsk added a subscriber: cfe-commits.
vsk updated this revision to Diff 47229.Feb 8 2016, 11:19 AM
  • Made the check a bit more general by moving it to propagateCounts.
  • Added 3 more tests.
vsk updated this revision to Diff 47230.Feb 8 2016, 11:24 AM
  • Check that we don't crash on a nested 'STMT' test case.
This revision was automatically updated to reflect the committed changes.