Author: Zequan Wu
Date: 2021-02-03T13:33:22-08:00
New Revision: 4dc08cc3aa41a28ca6ec82bb9c7183048761aad5

URL: 
https://github.com/llvm/llvm-project/commit/4dc08cc3aa41a28ca6ec82bb9c7183048761aad5
DIFF: 
https://github.com/llvm/llvm-project/commit/4dc08cc3aa41a28ca6ec82bb9c7183048761aad5.diff

LOG: [Coverage] Propogate counter to condition of conditional operator

Clang usually propagates counter mapping region for conditions of `if`, `while`,
`for`, etc from parent counter. We should do the same for condition of 
conditional operator.

Differential Revision: https://reviews.llvm.org/D95918

Added: 
    

Modified: 
    clang/lib/CodeGen/CoverageMappingGen.cpp
    clang/test/CoverageMapping/if.cpp
    clang/test/CoverageMapping/macro-expressions.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 5c25c204cc0b..4ebdaf64879d 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1462,7 +1462,7 @@ struct CounterCoverageMappingBuilder
     Counter ParentCount = getRegion().getCounter();
     Counter TrueCount = getRegionCounter(E);
 
-    Visit(E->getCond());
+    propagateCounts(ParentCount, E->getCond());
 
     if (!isa<BinaryConditionalOperator>(E)) {
       // The 'then' count applies to the area immediately after the condition.

diff  --git a/clang/test/CoverageMapping/if.cpp 
b/clang/test/CoverageMapping/if.cpp
index 0dd9b016a5ac..3c3a76a8c46a 100644
--- a/clang/test/CoverageMapping/if.cpp
+++ b/clang/test/CoverageMapping/if.cpp
@@ -3,7 +3,8 @@
 int nop() { return 0; }
 
 // CHECK-LABEL: _Z3foov:
-                                // CHECK-NEXT: [[@LINE+2]]:12 -> [[@LINE+7]]:2 
= #0
+                                // CHECK-NEXT: [[@LINE+3]]:12 -> [[@LINE+8]]:2 
= #0
+                                // CHECK-NEXT: [[@LINE+3]]:15 -> 
[[@LINE+3]]:19 = #0
                                 // CHECK-NEXT: Branch,File 0, [[@LINE+2]]:15 
-> [[@LINE+2]]:19 = 0, 0
 void foo() {                    // CHECK-NEXT: Gap,File 0, [[@LINE+1]]:20 -> 
[[@LINE+1]]:22 = #2
   if (int j = true ? nop()      // CHECK-NEXT: [[@LINE]]:22 -> [[@LINE]]:27 = 
#2
@@ -38,11 +39,13 @@ int main() {                    // CHECK: File 0, 
[[@LINE]]:12 -> {{[0-9]+}}:2 =
     i = 3;                      // CHECK-NEXT: File 0, [[@LINE-1]]:10 -> 
[[@LINE+1]]:4 = (#0 - #4)
   }
 
+                                // CHECK-NEXT: File 0, [[@LINE+2]]:7 -> 
[[@LINE+2]]:13 = #0
                                 // CHECK-NEXT: Branch,File 0, [[@LINE+1]]:7 -> 
[[@LINE+1]]:13 = #5, (#0 - #5)
   i = i == 0?                   // CHECK-NEXT: Gap,File 0, [[@LINE]]:13 -> 
[[@LINE+1]]:9 = #5
         i + 1 :                 // CHECK-NEXT: File 0, [[@LINE]]:9 -> 
[[@LINE]]:14 = #5
         i + 2;                  // CHECK-NEXT: File 0, [[@LINE]]:9 -> 
[[@LINE]]:14 = (#0 - #5)
 
+                                // CHECK-NEXT: File 0, [[@LINE+4]]:7 -> 
[[@LINE+4]]:13 = #0
                                 // CHECK-NEXT: Branch,File 0, [[@LINE+3]]:7 -> 
[[@LINE+3]]:13 = #6, (#0 - #6)
                                 // CHECK-NEXT: Gap,File 0, [[@LINE+2]]:13 -> 
[[@LINE+2]]:14 = #6
                                 // CHECK-NEXT: File 0, [[@LINE+1]]:14 -> 
[[@LINE+1]]:20 = #6

diff  --git a/clang/test/CoverageMapping/macro-expressions.cpp 
b/clang/test/CoverageMapping/macro-expressions.cpp
index 18c2a7fa8e3a..2f509281274c 100644
--- a/clang/test/CoverageMapping/macro-expressions.cpp
+++ b/clang/test/CoverageMapping/macro-expressions.cpp
@@ -83,20 +83,23 @@ void foo(int i) {
   // CHECK: File 0, [[@LINE+1]]:42 -> [[@LINE+1]]:44 = #7
   for (DECL(int, j) : ARR(int, 1, 2, 3)) {}
 
+  // CHECK-NEXT: File 0, [[@LINE+4]]:10 -> [[@LINE+4]]:11 = #0
   // CHECK-NEXT: Branch,File 0, [[@LINE+3]]:10 -> [[@LINE+3]]:11 = #8, (#0 - 
#8)
   // CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:14 -> [[@LINE+2]]:20 = #0
   // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:23 -> [[@LINE+1]]:29 = #0
   (void)(i ? PRIo64 : PRIu64);
 
+  // CHECK-NEXT: File 0, [[@LINE+6]]:10 -> [[@LINE+6]]:11 = #0
   // CHECK: File 0, [[@LINE+5]]:14 -> [[@LINE+5]]:15 = #9
-  // CHECK-NEXT: Expansion,File 0, [[@LINE+4]]:18 -> [[@LINE+4]]:22 = (#0 - #9)
-  // CHECK-NEXT: File 0, [[@LINE+3]]:22 -> [[@LINE+3]]:33 = (#0 - #9)
+  // CHECK-NEXT: File 0, [[@LINE+4]]:18 -> [[@LINE+4]]:33 = (#0 - #9)
+  // CHECK-NEXT: Expansion,File 0, [[@LINE+3]]:18 -> [[@LINE+3]]:22 = (#0 - #9)
   // CHECK: File 0, [[@LINE+2]]:28 -> [[@LINE+2]]:29 = #10
   // CHECK-NEXT: File 0, [[@LINE+1]]:32 -> [[@LINE+1]]:33 = ((#0 - #9) - #10)
   (void)(i ? i : EXPR(i) ? i : 0);
+  // CHECK-NEXT: File 0, [[@LINE+5]]:10 -> [[@LINE+5]]:11 = #0
   // CHECK-NEXT: Branch,File 0, [[@LINE+4]]:10 -> [[@LINE+4]]:11 = #11, (#0 - 
#11)
-  // CHECK-NEXT: Expansion,File 0, [[@LINE+3]]:15 -> [[@LINE+3]]:19 = (#0 - 
#11)
-  // CHECK-NEXT: File 0, [[@LINE+2]]:19 -> [[@LINE+2]]:27 = (#0 - #11)
+  // CHECK-NEXT: File 0, [[@LINE+3]]:15 -> [[@LINE+3]]:27 = (#0 - #11)
+  // CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:15 -> [[@LINE+2]]:19 = (#0 - 
#11)
   // CHECK-NEXT: File 0, [[@LINE+1]]:26 -> [[@LINE+1]]:27 = ((#0 - #11) - #12)
   (void)(i ?: EXPR(i) ?: 0);
 }


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to