summaryrefslogtreecommitdiffstats
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
commit39f01975ef346beea052004e233471b900929b85 (patch)
treeed6665dfa13ff6c47601305c2a367495dca89dcd
parente4ddfd14f162562749cb219e909dd0c2fe844d30 (diff)
downloadbcm5719-llvm-39f01975ef346beea052004e233471b900929b85.tar.gz
bcm5719-llvm-39f01975ef346beea052004e233471b900929b85.zip
[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 llvm-svn: 260129
-rw-r--r--clang/lib/CodeGen/CoverageMappingGen.cpp6
-rw-r--r--clang/test/CoverageMapping/macro-expressions.cpp38
2 files changed, 44 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 2fa6f27c5af..9279d1a37cf 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/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;
}
diff --git a/clang/test/CoverageMapping/macro-expressions.cpp b/clang/test/CoverageMapping/macro-expressions.cpp
index 6626bfefd6c..3852fc6a23b 100644
--- a/clang/test/CoverageMapping/macro-expressions.cpp
+++ b/clang/test/CoverageMapping/macro-expressions.cpp
@@ -12,6 +12,44 @@
#define PRIo64 PRI_64_LENGTH_MODIFIER "o"
#define PRIu64 PRI_64_LENGTH_MODIFIER "u"
+#define STMT(s) s
+
+void fn1() {
+ STMT(if (1));
+ STMT(while (1));
+ STMT(for (;;));
+ STMT(if) (1);
+ STMT(while) (1);
+ STMT(for) (;;);
+ if (1)
+ STMT(if (1)
+ STMT(if (1)));
+ if (1)
+ STMT(if (1)) 0;
+ if (1)
+ STMT(while (1)) 0;
+ if (1)
+ STMT(for (;;)) 0;
+ while (1)
+ STMT(if (1)) 0;
+ while (1)
+ STMT(while (1)) 0;
+ while (1)
+ STMT(for (;;)) 0;
+ for (;;)
+ STMT(if (1)) 0;
+ for (;;)
+ STMT(while (1)) 0;
+ for (;;)
+ STMT(for (;;)) 0;
+}
+
+void STMT(fn2()) {
+}
+
+void STMT(fn3)() {
+}
+
// CHECK: foo
// CHECK-NEXT: File 0, [[@LINE+1]]:17 -> {{[0-9]+}}:2 = #0
void foo(int i) {
OpenPOWER on IntegriCloud