r273463 - [Coverage] Push a new region when handling CXXTryStmts
Vedant Kumar via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 22 12:57:59 PDT 2016
Author: vedantk
Date: Wed Jun 22 14:57:58 2016
New Revision: 273463
URL: http://llvm.org/viewvc/llvm-project?rev=273463&view=rev
Log:
[Coverage] Push a new region when handling CXXTryStmts
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.
Modified:
cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
cfe/trunk/test/CoverageMapping/trycatch.cpp
cfe/trunk/test/CoverageMapping/trymacro.cpp
Modified: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp?rev=273463&r1=273462&r2=273463&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp (original)
+++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp Wed Jun 22 14:57:58 2016
@@ -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));
Modified: cfe/trunk/test/CoverageMapping/trycatch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/trycatch.cpp?rev=273463&r1=273462&r2=273463&view=diff
==============================================================================
--- cfe/trunk/test/CoverageMapping/trycatch.cpp (original)
+++ cfe/trunk/test/CoverageMapping/trycatch.cpp Wed Jun 22 14:57:58 2016
@@ -23,7 +23,7 @@ void func(int i) { //
// 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;
Modified: cfe/trunk/test/CoverageMapping/trymacro.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/trymacro.cpp?rev=273463&r1=273462&r2=273463&view=diff
==============================================================================
--- cfe/trunk/test/CoverageMapping/trymacro.cpp (original)
+++ cfe/trunk/test/CoverageMapping/trymacro.cpp Wed Jun 22 14:57:58 2016
@@ -17,8 +17,27 @@ catch(...) {} // CHECK: [[
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();
}
More information about the cfe-commits
mailing list