Author: NAKAMURA Takumi
Date: 2026-01-19T18:31:20+09:00
New Revision: 593103465326850f23bc9a6078ae7fb01065d46e

URL: 
https://github.com/llvm/llvm-project/commit/593103465326850f23bc9a6078ae7fb01065d46e
DIFF: 
https://github.com/llvm/llvm-project/commit/593103465326850f23bc9a6078ae7fb01065d46e.diff

LOG: CoverageMappingWriter.cpp: Append yet another comarison, endLoc.

This was the part of #125407.

For "Same Kind and same startLoc", reorder records BY endLoc DESC, to
prioritize wider Regions with the same startLoc.

Added: 
    

Modified: 
    clang/test/CoverageMapping/ctor.cpp
    clang/test/CoverageMapping/includehell.cpp
    clang/test/CoverageMapping/macros.c
    llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp

Removed: 
    


################################################################################
diff  --git a/clang/test/CoverageMapping/ctor.cpp 
b/clang/test/CoverageMapping/ctor.cpp
index 1cf12cd738c2c..191f73f5693e1 100644
--- a/clang/test/CoverageMapping/ctor.cpp
+++ b/clang/test/CoverageMapping/ctor.cpp
@@ -11,8 +11,8 @@ class B: public A {
     int c;
     B(int x, int y)
     : A(x),                 // CHECK:      File 0, [[@LINE]]:7 -> [[@LINE]]:11 
= #0
-                            // CHECK-NEXT: File 0, [[@LINE+1]]:7 -> 
[[@LINE+1]]:13 = #0
-    b(x == 0? 1: 2),        // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:19 
= #0
+                            // CHECK-NEXT: File 0, [[@LINE+1]]:7 -> 
[[@LINE+1]]:19 = #0
+    b(x == 0? 1: 2),        // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:13 
= #0
                             // CHECK-NEXT: Branch,File 0, [[@LINE-1]]:7 -> 
[[@LINE-1]]:13 = #1, (#0 - #1)
                             // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:14 -> 
[[@LINE-2]]:15 = #1
                             // CHECK-NEXT: File 0, [[@LINE-3]]:15 -> 
[[@LINE-3]]:16 = #1

diff  --git a/clang/test/CoverageMapping/includehell.cpp 
b/clang/test/CoverageMapping/includehell.cpp
index 09e03e77799d5..3c67672fabc0f 100644
--- a/clang/test/CoverageMapping/includehell.cpp
+++ b/clang/test/CoverageMapping/includehell.cpp
@@ -28,14 +28,14 @@ int main() {
 // CHECK-MAIN-NEXT: Expansion,File [[MAIN]], 6:12 -> 6:35 = #0
 // CHECK-MAIN-NEXT: File [[MAIN]], 6:35 -> 10:33 = #1
 // CHECK-MAIN-NEXT: Expansion,File [[MAIN]], 8:14 -> 8:29 = #1
-// CHECK-MAIN-NEXT: Expansion,File [[MAIN]], 10:12 -> 10:33 = #1
+// CHECK-MAIN-NEXT: Expansion,File [[MAIN]], 10:12 -> 10:33 = #0
 // CHECK-MAIN-NEXT: Expansion,File [[MAIN]], 12:12 -> 12:35 = #0
 // CHECK-MAIN-NEXT: File [[MAIN]], 12:35 -> 14:33 = #5
 // CHECK-MAIN-NEXT: Expansion,File [[MAIN]], 13:14 -> 13:29 = #5
-// CHECK-MAIN-NEXT: Expansion,File [[MAIN]], 14:12 -> 14:33 = #5
+// CHECK-MAIN-NEXT: Expansion,File [[MAIN]], 14:12 -> 14:33 = #0
 // CHECK-MAIN-NEXT: Expansion,File [[MAIN]], 16:12 -> 16:35 = #0
 // CHECK-MAIN-NEXT: File [[MAIN]], 16:35 -> 17:33 = #9
-// CHECK-MAIN-NEXT: Expansion,File [[MAIN]], 17:12 -> 17:33 = #9
+// CHECK-MAIN-NEXT: Expansion,File [[MAIN]], 17:12 -> 17:33 = #0
 
 // CHECK-START: File [[START1:[0-9]]], 1:1 -> 5:1 = #0
 // CHECK-START: File [[START1]], 4:17 -> 4:22 = (#0 + #1)
@@ -65,15 +65,15 @@ int main() {
 // CHECK-CODE: File [[CODE2]], 9:11 -> 11:2 = #7
 // CHECK-CODE: File [[CODE2]], 11:8 -> 13:2 = (#5 - #7)
 
-// CHECK-END: File [[END1:[0-9]]], 1:1 -> 3:2 = #1
-// CHECK-END: File [[END1]], 1:1 -> 6:1 = #0
+// CHECK-END: File [[END1:[0-9]]], 1:1 -> 6:1 = #0
+// CHECK-END: File [[END1]], 1:1 -> 3:2 = #1
 // CHECK-END: File [[END1]], 5:5 -> 5:9 = #0
 // CHECK-END: File [[END1]], 5:11 -> 5:16 = #4
-// CHECK-END: File [[END2:[0-9]]], 1:1 -> 3:2 = #5
-// CHECK-END: File [[END2]], 1:1 -> 6:1 = #0
+// CHECK-END: File [[END2:[0-9]]], 1:1 -> 6:1 = #0
+// CHECK-END: File [[END2]], 1:1 -> 3:2 = #5
 // CHECK-END: File [[END2]], 5:5 -> 5:9 = #0
 // CHECK-END: File [[END2]], 5:11 -> 5:16 = #8
-// CHECK-END: File [[END3:[0-9]]], 1:1 -> 3:2 = #9
-// CHECK-END: File [[END3]], 1:1 -> 6:1 = #0
+// CHECK-END: File [[END3:[0-9]]], 1:1 -> 6:1 = #0
+// CHECK-END: File [[END3]], 1:1 -> 3:2 = #9
 // CHECK-END: File [[END3]], 5:5 -> 5:9 = #0
 // CHECK-END: File [[END3]], 5:11 -> 5:16 = #10

diff  --git a/clang/test/CoverageMapping/macros.c 
b/clang/test/CoverageMapping/macros.c
index fcf21170ef135..00139f33229d5 100644
--- a/clang/test/CoverageMapping/macros.c
+++ b/clang/test/CoverageMapping/macros.c
@@ -80,12 +80,12 @@ void func7(void) { // CHECK-NEXT: File 0, [[@LINE]]:18 -> 
[[@LINE+6]]:2 = #0
   int kk,ll;       // CHECK-NEXT: File 0, [[@LINE+1]]:7 -> [[@LINE+1]]:8 = #0
   if (k)           // CHECK-NEXT: Branch,File 0, [[@LINE]]:7 -> [[@LINE]]:8 = 
#1
     m(k);          // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:9 -> [[@LINE]]:5 = #1
-  else             // CHECK-NEXT: Expansion,File 0, [[@LINE-1]]:5 -> 
[[@LINE-1]]:6 = #1
+  else             // CHECK-NEXT: Expansion,File 0, [[@LINE-1]]:5 -> 
[[@LINE-1]]:6 = #0
     l = m(l);      // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:7 -> [[@LINE]]:5 = 
(#0 - #1)
 }                  // CHECK-NEXT: File 0, [[@LINE-1]]:5 -> [[@LINE-1]]:10 = 
(#0 - #1)
                    // CHECK-NEXT: Expansion,File 0, [[@LINE-2]]:9 -> 
[[@LINE-2]]:10 = (#0 - #1)
-                   // CHECK-NEXT: File 1, [[@LINE-9]]:14 -> [[@LINE-9]]:17 = #1
-                   // CHECK-NEXT: File 1, [[@LINE-10]]:14 -> [[@LINE-10]]:18 = 
#0
+                   // CHECK-NEXT: File 1, [[@LINE-9]]:14 -> [[@LINE-9]]:18 = #0
+                   // CHECK-NEXT: File 1, [[@LINE-10]]:14 -> [[@LINE-10]]:17 = 
#1
                    // CHECK-NEXT: File 2, [[@LINE-11]]:14 -> [[@LINE-11]]:17 = 
(#0 - #1)
                    // CHECK-NEXT: File 2, [[@LINE-12]]:14 -> [[@LINE-12]]:15 = 
(#0 - #1)
 

diff  --git a/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp 
b/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
index 3875f01c48528..dc97870985145 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
@@ -174,7 +174,14 @@ void CoverageMappingWriter::write(raw_ostream &OS) {
                   : 2 * Kind);
     };
 
-    return getKindKey(LHS.Kind) < getKindKey(RHS.Kind);
+    auto LHSKindKey = getKindKey(LHS.Kind);
+    auto RHSKindKey = getKindKey(RHS.Kind);
+    if (LHSKindKey != RHSKindKey)
+      return LHSKindKey < RHSKindKey;
+
+    // Compares endLoc in descending order,
+    // to prioritize wider Regions with the same startLoc.
+    return LHS.endLoc() > RHS.endLoc();
   });
 
   // Write out the fileid -> filename mapping.


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to