]> granicus.if.org Git - clang/commitdiff
[Coverage] Push a new region when handling CXXTryStmts
authorVedant Kumar <vsk@apple.com>
Wed, 22 Jun 2016 19:57:58 +0000 (19:57 +0000)
committerVedant Kumar <vsk@apple.com>
Wed, 22 Jun 2016 19:57:58 +0000 (19:57 +0000)
Push a new region for the try block and propagate execution counts
through it. This ensures that catch statements get a region counter
distinct from the try block's counter.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@273463 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CoverageMappingGen.cpp
test/CoverageMapping/trycatch.cpp
test/CoverageMapping/trymacro.cpp

index 12bad4b03f7c3ba06f66c26b34e18caba743bdbf..b56cd077c8b4acc477dd85844bb69170117c6db3 100644 (file)
@@ -867,7 +867,12 @@ struct CounterCoverageMappingBuilder
 
   void VisitCXXTryStmt(const CXXTryStmt *S) {
     extendRegion(S);
-    Visit(S->getTryBlock());
+    // Handle macros that generate the "try" but not the rest.
+    extendRegion(S->getTryBlock());
+
+    Counter ParentCount = getRegion().getCounter();
+    propagateCounts(ParentCount, S->getTryBlock());
+
     for (unsigned I = 0, E = S->getNumHandlers(); I < E; ++I)
       Visit(S->getHandler(I));
 
index e3a3f09c9f9f3ee70825cce1b084cacacc09fedd..01d8fb9307401705fa73c54b69d847b8e6497200 100644 (file)
@@ -23,7 +23,7 @@ void func(int i) {                    // CHECK-NEXT: File 0, [[@LINE]]:18 -> {{[
                                       // CHECK-NEXT: main
 int main() {                          // CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+13]]:2 = #0
   int j = 1;
-  try {
+  try {                               // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE+2]]:4 = #0
     func(j);
   } catch(const Error &e) {           // CHECK-NEXT: File 0, [[@LINE]]:27 -> [[@LINE+2]]:4 = #2
     j = 1;
index 1fe668353fa4d98521dd56bc8f8cab2e20861f87..32f44381b93887de1834cf7bf502508d1865fbd5 100644 (file)
@@ -17,8 +17,27 @@ catch(...) {}               // CHECK: [[@LINE]]:12 -> [[@LINE]]:14 = #2
 void fn3() TRY { return; } // CHECK: [[@LINE]]:15 -> [[@LINE+1]]:14 = #1
 CATCH(...) {}              // CHECK: [[@LINE]]:12 -> [[@LINE]]:14 = #2
 
+// CHECK: Z3fn4v:
+#define TRY2 try { // CHECK-DAG: File 1, [[@LINE]]:18 -> [[@LINE]]:19 = #1
+void fn4() TRY2 // CHECK-DAG: Expansion,File 0, [[@LINE]]:12 -> [[@LINE]]:16 = #1 (Expanded file = 1)
+  for (;;)
+    return;
+}
+catch (...) {}
+
+// CHECK: Z3fn5v:
+#define TRY3 try { return; } catch (...) // CHECK-DAG: File 2, [[@LINE]]:18 -> [[@LINE]]:29 = #1
+#define TRY4 try { TRY3 { return; } } catch (...) // CHECK-DAG: Expansion,File 1, [[@LINE]]:20 -> [[@LINE]]:24 = #1 (Expanded file = 2)
+void fn5() {
+  for (;;) {
+    TRY4 { return; } // CHECK-DAG: Expansion,File 0, [[@LINE]]:5 -> [[@LINE]]:9 = #1 (Expanded file = 1)
+  }                  // CHECK-DAG: File 0, [[@LINE-1]]:10 -> [[@LINE-1]]:21 = #5
+}
+
 int main() {
   fn1();
   fn2();
   fn3();
+  fn4();
+  fn5();
 }