summaryrefslogtreecommitdiffstats
path: root/lib/CodeGen/CoverageMappingGen.cpp
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2016-02-08 19:25:45 +0000
committerVedant Kumar <vsk@apple.com>2016-02-08 19:25:45 +0000
commit61cd9c9fc26ea67faac6463837af5cd0b3806fd7 (patch)
tree54107e7cd4dae8cc393f3bdd87d9b6f065ca0fc5 /lib/CodeGen/CoverageMappingGen.cpp
parentd5976a00f2e9fc928164132ca1157eafec34e030 (diff)
[Coverage] Fix crash when handling certain macro expansions
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 Differential Revision: http://reviews.llvm.org/D16934 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@260129 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CoverageMappingGen.cpp')
-rw-r--r--lib/CodeGen/CoverageMappingGen.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/CodeGen/CoverageMappingGen.cpp b/lib/CodeGen/CoverageMappingGen.cpp
index 2fa6f27c5a..9279d1a37c 100644
--- a/lib/CodeGen/CoverageMappingGen.cpp
+++ b/lib/CodeGen/CoverageMappingGen.cpp
@@ -434,6 +434,12 @@ struct CounterCoverageMappingBuilder
Visit(S);
Counter ExitCount = getRegion().getCounter();
popRegions(Index);
+
+ // The statement may be spanned by an expansion. Make sure we handle a file
+ // exit out of this expansion before moving to the next statement.
+ if (SM.isBeforeInTranslationUnit(getStart(S), S->getLocStart()))
+ MostRecentLocation = getEnd(S);
+
return ExitCount;
}