[PATCH] D20880: [Coverage] Push a region and propagate counts through try blocks

Vedant Kumar via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 1 14:59:42 PDT 2016


vsk created this revision.
vsk added reviewers: ikudrin, bogner, MaggieYi, phillip.power.
vsk added a subscriber: cfe-commits.

This lets us handle expansions in the try block properly. Here's how the final report changes:

```
Before:

       |   16|// CHECK: Z3fn3v:
      1|   17|void fn3() TRY { return; } // CHECK: [[@LINE]]:15 -> [[@LINE+1]]:14 = #1
                         ^1 ^1
      0|   18|CATCH(...) {}              // CHECK: [[@LINE]]:12 -> [[@LINE]]:14 = #2
       |   19|
       |   20|// CHECK: Z3fn4v:
      1|   21|#define TRY2 try { // CHECK-DAG: File 1, [[@LINE]]:18 -> [[@LINE]]:19 = #1
      1|   22|void fn4() TRY2 // CHECK-DAG: Expansion,File 0, [[@LINE]]:12 -> [[@LINE]]:16 = #1 (Expanded file = 1)
                         ^1  ^1
      1|   23|  for (;;)
      1|   24|    return;
      1|   25|}
      0|   26|catch (...) {}
       |   27|
       |   28|// CHECK: Z3fn5v:
       |   29|#define TRY3 try { return; } catch (...) // CHECK-DAG: File 2, [[@LINE]]:18 -> [[@LINE]]:29 = #1
      0|   30|#define TRY4 try { TRY3 { return; } } catch (...) // CHECK-DAG: Expansion,File 1, [[@LINE]]:20 -> [[@LINE]]:24 = #1 (Expanded file = 2)
      1|   31|void fn5() {
      1|   32|  for (;;) {
      0|   33|    TRY4 { return; } // CHECK-DAG: Expansion,File 0, [[@LINE]]:5 -> [[@LINE]]:9 = #1 (Expanded file = 1)
                  ^0   ^0
      1|   34|  }                  // CHECK-DAG: File 0, [[@LINE-1]]:10 -> [[@LINE-1]]:21 = #5
      1|   35|}


After:

       |   20|// CHECK: Z3fn4v:
      1|   21|#define TRY2 try { // CHECK-DAG: File 1, [[@LINE]]:18 -> [[@LINE]]:19 = #1
                           ^1  ^1
      1|   22|void fn4() TRY2 // CHECK-DAG: Expansion,File 0, [[@LINE]]:12 -> [[@LINE]]:16 = #1 (Expanded file = 1)
                         ^1  ^1
      1|   23|  for (;;)
      1|   24|    return;
      1|   25|}
      0|   26|catch (...) {}
       |   27|
       |   28|// CHECK: Z3fn5v:
      1|   29|#define TRY3 try { return; } catch (...) // CHECK-DAG: File 2, [[@LINE]]:18 -> [[@LINE]]:29 = #1
      1|   30|#define TRY4 try { TRY3 { return; } } catch (...) // CHECK-DAG: Expansion,File 1, [[@LINE]]:20 -> [[@LINE]]:24 = #1 (Expanded file = 2)
                               ^1^1   ^0
      1|   31|void fn5() {
      1|   32|  for (;;) {
      1|   33|    TRY4 { return; } // CHECK-DAG: Expansion,File 0, [[@LINE]]:5 -> [[@LINE]]:9 = #1 (Expanded file = 1)
                  ^1   ^0
      1|   34|  }                  // CHECK-DAG: File 0, [[@LINE-1]]:10 -> [[@LINE-1]]:21 = #5
      1|   35|}
```

http://reviews.llvm.org/D20880

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

Index: test/CoverageMapping/trymacro.cpp
===================================================================
--- test/CoverageMapping/trymacro.cpp
+++ test/CoverageMapping/trymacro.cpp
@@ -17,8 +17,27 @@
 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();
 }
Index: test/CoverageMapping/trycatch.cpp
===================================================================
--- test/CoverageMapping/trycatch.cpp
+++ test/CoverageMapping/trycatch.cpp
@@ -23,7 +23,7 @@
                                       // 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: lib/CodeGen/CoverageMappingGen.cpp
===================================================================
--- lib/CodeGen/CoverageMappingGen.cpp
+++ lib/CodeGen/CoverageMappingGen.cpp
@@ -847,7 +847,12 @@
 
   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));
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20880.59285.patch
Type: text/x-patch
Size: 2361 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160601/aa40e6f4/attachment-0001.bin>


More information about the cfe-commits mailing list