From 1587432d1f3a5b1fe89b4e12cbf8265c86da9695 Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Thu, 30 Apr 2015 21:31:02 +0000 Subject: [PATCH] InstrProf: Make sure coverage propagates out of foreach loops correctly llvm-svn: 236264 --- clang/lib/CodeGen/CoverageMappingGen.cpp | 12 ++++++++---- clang/test/CoverageMapping/loops.cpp | 15 +++++++++++---- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp index 73afeda35725..340a659584b3 100644 --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -714,8 +714,10 @@ struct CounterCoverageMappingBuilder Counter BackedgeCount = propagateCounts(BodyCount, S->getBody()); BreakContinue BC = BreakContinueStack.pop_back_val(); - Counter OutCount = addCounters(ParentCount, BC.BreakCount, BC.ContinueCount, - subtractCounters(BodyCount, BackedgeCount)); + Counter LoopCount = + addCounters(ParentCount, BackedgeCount, BC.ContinueCount); + Counter OutCount = + addCounters(BC.BreakCount, subtractCounters(LoopCount, BodyCount)); if (OutCount != ParentCount) pushRegion(OutCount); } @@ -732,8 +734,10 @@ struct CounterCoverageMappingBuilder Counter BackedgeCount = propagateCounts(BodyCount, S->getBody()); BreakContinue BC = BreakContinueStack.pop_back_val(); - Counter OutCount = addCounters(ParentCount, BC.BreakCount, BC.ContinueCount, - subtractCounters(BodyCount, BackedgeCount)); + Counter LoopCount = + addCounters(ParentCount, BackedgeCount, BC.ContinueCount); + Counter OutCount = + addCounters(BC.BreakCount, subtractCounters(LoopCount, BodyCount)); if (OutCount != ParentCount) pushRegion(OutCount); } diff --git a/clang/test/CoverageMapping/loops.cpp b/clang/test/CoverageMapping/loops.cpp index d619879f37f6..84a9892526ce 100644 --- a/clang/test/CoverageMapping/loops.cpp +++ b/clang/test/CoverageMapping/loops.cpp @@ -1,15 +1,22 @@ // RUN: %clang_cc1 -std=c++11 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name loops.cpp %s | FileCheck %s // CHECK: rangedFor -void rangedFor() { // CHECK-NEXT: File 0, [[@LINE]]:18 -> [[@LINE+6]]:2 = #0 +void rangedFor() { // CHECK-NEXT: File 0, [[@LINE]]:18 -> {{[0-9]+}}:2 = #0 int arr[] = { 1, 2, 3, 4, 5 }; int sum = 0; - for(auto i : arr) { // CHECK-NEXT: File 0, [[@LINE]]:21 -> [[@LINE+2]]:4 = #1 - sum += i; + for(auto i : arr) { // CHECK: File 0, [[@LINE]]:21 -> [[@LINE+6]]:4 = #1 + if (i == 3) + continue; // CHECK: File 0, [[@LINE]]:7 -> [[@LINE]]:15 = #2 + sum += i; // CHECK: File 0, [[@LINE]]:5 -> {{[0-9]+}}:4 = (#1 - #2) + if (sum >= 7) + break; // CHECK: File 0, [[@LINE]]:7 -> [[@LINE]]:12 = #3 } + + // CHECK: File 0, [[@LINE+1]]:7 -> [[@LINE+1]]:10 = #0 + if (sum) {} } - // CHECK-NEXT: main + // CHECK: main: int main() { // CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+24]]:2 = #0 // CHECK-NEXT: File 0, [[@LINE+1]]:18 -> [[@LINE+1]]:24 = (#0 + #1) for(int i = 0; i < 10; ++i) // CHECK-NEXT: File 0, [[@LINE]]:26 -> [[@LINE]]:29 = #1 -- 2.34.1