From: Vedant Kumar Date: Wed, 22 Jun 2016 19:57:58 +0000 (+0000) Subject: [Coverage] Push a new region when handling CXXTryStmts X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c35b5c603db3fa9afd201ab99c154e63f21df50d;p=clang [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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@273463 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CoverageMappingGen.cpp b/lib/CodeGen/CoverageMappingGen.cpp index 12bad4b03f..b56cd077c8 100644 --- a/lib/CodeGen/CoverageMappingGen.cpp +++ b/lib/CodeGen/CoverageMappingGen.cpp @@ -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)); diff --git a/test/CoverageMapping/trycatch.cpp b/test/CoverageMapping/trycatch.cpp index e3a3f09c9f..01d8fb9307 100644 --- a/test/CoverageMapping/trycatch.cpp +++ b/test/CoverageMapping/trycatch.cpp @@ -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; diff --git a/test/CoverageMapping/trymacro.cpp b/test/CoverageMapping/trymacro.cpp index 1fe668353f..32f44381b9 100644 --- a/test/CoverageMapping/trymacro.cpp +++ b/test/CoverageMapping/trymacro.cpp @@ -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(); }