]> granicus.if.org Git - clang/commitdiff
InstrProf: Make sure coverage propagates out of foreach loops correctly
authorJustin Bogner <mail@justinbogner.com>
Thu, 30 Apr 2015 21:31:02 +0000 (21:31 +0000)
committerJustin Bogner <mail@justinbogner.com>
Thu, 30 Apr 2015 21:31:02 +0000 (21:31 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236264 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CoverageMappingGen.cpp
test/CoverageMapping/loops.cpp

index 73afeda357255b127f99b4d23b25f4092dfd0ced..340a659584b36182db8d4ed955ecce41926c56fa 100644 (file)
@@ -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);
   }
index d619879f37f6501ea2773baf1f2a68ec0ddd6ae2..84a9892526ce475639e7d265fbdae2912ec04942 100644 (file)
@@ -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