From: Justin Bogner Date: Thu, 30 Apr 2015 21:31:02 +0000 (+0000) Subject: InstrProf: Make sure coverage propagates out of foreach loops correctly X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dd4d8b2b5f47f91a7f793dbe27720492d2b0459a;p=clang InstrProf: Make sure coverage propagates out of foreach loops correctly git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236264 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CoverageMappingGen.cpp b/lib/CodeGen/CoverageMappingGen.cpp index 73afeda357..340a659584 100644 --- a/lib/CodeGen/CoverageMappingGen.cpp +++ b/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/test/CoverageMapping/loops.cpp b/test/CoverageMapping/loops.cpp index d619879f37..84a9892526 100644 --- a/test/CoverageMapping/loops.cpp +++ b/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