[PATCH] D46918: [Coverage] Discard the last uncompleted deferred region in a decl

2018-05-30 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL333609: [Coverage] Discard the last uncompleted deferred 
region in a decl (authored by vedantk, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46918?vs=147360=149216#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46918

Files:
  cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
  cfe/trunk/test/CoverageMapping/deferred-region.cpp
  cfe/trunk/test/CoverageMapping/label.cpp
  cfe/trunk/test/CoverageMapping/moremacros.c
  cfe/trunk/test/CoverageMapping/trycatch.cpp

Index: cfe/trunk/test/CoverageMapping/moremacros.c
===
--- cfe/trunk/test/CoverageMapping/moremacros.c
+++ cfe/trunk/test/CoverageMapping/moremacros.c
@@ -31,7 +31,7 @@
   if (!argc) {
 return 0;
   // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:8 = #4
-  RBRAC // CHECK-NEXT: [[@LINE]]:8 -> [[@LINE+1]]:2 = (((#0 - #2) - #3) - #4)
+  RBRAC
 }
 
 // CHECK-NEXT: File 1, 3:15 -> 3:16 = #2
Index: cfe/trunk/test/CoverageMapping/trycatch.cpp
===
--- cfe/trunk/test/CoverageMapping/trycatch.cpp
+++ cfe/trunk/test/CoverageMapping/trycatch.cpp
@@ -18,7 +18,7 @@
   // CHECK: File 0, [[@LINE+1]]:10 -> [[@LINE+2]]:27 = (#0 - #1)
   } else if(i == 8)   // CHECK-NEXT: File 0, [[@LINE]]:13 -> [[@LINE]]:19 = (#0 - #1)
 throw ImportantError();   // CHECK: File 0, [[@LINE]]:5 -> [[@LINE]]:27 = #2
-} // CHECK-NEXT: File 0, [[@LINE-1]]:27 -> [[@LINE]]:2 = ((#0 - #1) - #2)
+}
 
   // CHECK-NEXT: main
 int main() {  // CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+13]]:2 = #0
Index: cfe/trunk/test/CoverageMapping/label.cpp
===
--- cfe/trunk/test/CoverageMapping/label.cpp
+++ cfe/trunk/test/CoverageMapping/label.cpp
@@ -16,19 +16,18 @@
   goto x;// CHECK: File 0, [[@LINE]]:7 -> [[@LINE]]:13 = (#1 - #2)
 int k = 3;   // CHECK-NEXT: File 0, [[@LINE-1]]:13 -> [[@LINE]]:5 = #3
   }  // CHECK-NEXT: File 0, [[@LINE-1]]:5 -> [[@LINE]]:4 = #3
-  static int j = 0;  // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+5]]:2 = ((#0 + #3) - #1)
+  static int j = 0;  // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+4]]:2 = ((#0 + #3) - #1)
   ++j;
   if(j == 1) // CHECK-NEXT: File 0, [[@LINE]]:6 -> [[@LINE]]:12 = ((#0 + #3) - #1)
 goto x;  // CHECK: File 0, [[@LINE]]:5 -> [[@LINE]]:11 = #4
- // CHECK-NEXT: File 0, [[@LINE-1]]:11 -> [[@LINE+1]]:2 = (((#0 + #3) - #1) - #4)
 }
 
  // CHECK-NEXT: test1
 void test1(int x) {  // CHECK-NEXT: File 0, [[@LINE]]:19 -> {{[0-9]+}}:2 = #0
   if(x == 0) // CHECK-NEXT: File 0, [[@LINE]]:6 -> [[@LINE]]:12 = #0
 goto a;  // CHECK: File 0, [[@LINE]]:5 -> [[@LINE]]:11 = #1
  // CHECK-NEXT: File 0, [[@LINE-1]]:11 -> [[@LINE+1]]:3 = (#0 - #1)
-  goto b;// CHECK: Gap,File 0, [[@LINE]]:3 -> [[@LINE+5]]:2 = #3
+  goto b;// CHECK: File 0, [[@LINE]]:3 -> [[@LINE+5]]:2 = (#0 - #1)
  // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:9 -> [[@LINE+1]]:1 = #2
 a:   // CHECK-NEXT: File 0, [[@LINE]]:1 -> [[@LINE+3]]:2 = #2
 b:   // CHECK-NEXT: File 0, [[@LINE]]:1 -> [[@LINE+2]]:2 = #3
Index: cfe/trunk/test/CoverageMapping/deferred-region.cpp
===
--- cfe/trunk/test/CoverageMapping/deferred-region.cpp
+++ cfe/trunk/test/CoverageMapping/deferred-region.cpp
@@ -7,19 +7,20 @@
 void foo(int x) {
   if (x == 0) {
 return;
-  } // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+2]]:2 = (#0 - #1)
-
+  } // CHECK-NOT: Gap,File 0, [[@LINE]]:4
+//< Don't complete the last deferred region in a decl, even though it may
+//< leave some whitespace marked with the same counter as the final return.
 }
 
-// CHECK-NEXT: _Z4foooi:
+// CHECK-LABEL: _Z4foooi:
 void fooo(int x) {
   if (x == 0) {
 return;
   } // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+2]]:3 = (#0 - #1)
 
   if (x == 1) {
 return;
-  } // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+2]]:2 = ((#0 - #1) - #2)
+  } // CHECK-NOT: Gap,File 0, [[@LINE]]:4
 
 }
 
@@ -108,7 +109,7 @@
   }
 
   if (false)
-return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+1]]:2
+return; // CHECK-NOT: Gap,File 0, [[@LINE]]:11
 }
 
 // CHECK-LABEL: _Z8for_loopv:
@@ -167,7 +168,18 @@
   return; // CHECK: [[@LINE]]:3 -> [[@LINE+4]]:2 = (#0 - #1)
 
 out:
-	return; // CHECK: Gap,File 0, [[@LINE]]:8 -> [[@LINE+1]]:2 = 0

[PATCH] D46918: [Coverage] Discard the last uncompleted deferred region in a decl

2018-05-30 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC333609: [Coverage] Discard the last uncompleted deferred 
region in a decl (authored by vedantk, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D46918

Files:
  lib/CodeGen/CoverageMappingGen.cpp
  test/CoverageMapping/deferred-region.cpp
  test/CoverageMapping/label.cpp
  test/CoverageMapping/moremacros.c
  test/CoverageMapping/trycatch.cpp

Index: test/CoverageMapping/moremacros.c
===
--- test/CoverageMapping/moremacros.c
+++ test/CoverageMapping/moremacros.c
@@ -31,7 +31,7 @@
   if (!argc) {
 return 0;
   // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:8 = #4
-  RBRAC // CHECK-NEXT: [[@LINE]]:8 -> [[@LINE+1]]:2 = (((#0 - #2) - #3) - #4)
+  RBRAC
 }
 
 // CHECK-NEXT: File 1, 3:15 -> 3:16 = #2
Index: test/CoverageMapping/trycatch.cpp
===
--- test/CoverageMapping/trycatch.cpp
+++ test/CoverageMapping/trycatch.cpp
@@ -18,7 +18,7 @@
   // CHECK: File 0, [[@LINE+1]]:10 -> [[@LINE+2]]:27 = (#0 - #1)
   } else if(i == 8)   // CHECK-NEXT: File 0, [[@LINE]]:13 -> [[@LINE]]:19 = (#0 - #1)
 throw ImportantError();   // CHECK: File 0, [[@LINE]]:5 -> [[@LINE]]:27 = #2
-} // CHECK-NEXT: File 0, [[@LINE-1]]:27 -> [[@LINE]]:2 = ((#0 - #1) - #2)
+}
 
   // CHECK-NEXT: main
 int main() {  // CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+13]]:2 = #0
Index: test/CoverageMapping/label.cpp
===
--- test/CoverageMapping/label.cpp
+++ test/CoverageMapping/label.cpp
@@ -16,19 +16,18 @@
   goto x;// CHECK: File 0, [[@LINE]]:7 -> [[@LINE]]:13 = (#1 - #2)
 int k = 3;   // CHECK-NEXT: File 0, [[@LINE-1]]:13 -> [[@LINE]]:5 = #3
   }  // CHECK-NEXT: File 0, [[@LINE-1]]:5 -> [[@LINE]]:4 = #3
-  static int j = 0;  // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+5]]:2 = ((#0 + #3) - #1)
+  static int j = 0;  // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+4]]:2 = ((#0 + #3) - #1)
   ++j;
   if(j == 1) // CHECK-NEXT: File 0, [[@LINE]]:6 -> [[@LINE]]:12 = ((#0 + #3) - #1)
 goto x;  // CHECK: File 0, [[@LINE]]:5 -> [[@LINE]]:11 = #4
- // CHECK-NEXT: File 0, [[@LINE-1]]:11 -> [[@LINE+1]]:2 = (((#0 + #3) - #1) - #4)
 }
 
  // CHECK-NEXT: test1
 void test1(int x) {  // CHECK-NEXT: File 0, [[@LINE]]:19 -> {{[0-9]+}}:2 = #0
   if(x == 0) // CHECK-NEXT: File 0, [[@LINE]]:6 -> [[@LINE]]:12 = #0
 goto a;  // CHECK: File 0, [[@LINE]]:5 -> [[@LINE]]:11 = #1
  // CHECK-NEXT: File 0, [[@LINE-1]]:11 -> [[@LINE+1]]:3 = (#0 - #1)
-  goto b;// CHECK: Gap,File 0, [[@LINE]]:3 -> [[@LINE+5]]:2 = #3
+  goto b;// CHECK: File 0, [[@LINE]]:3 -> [[@LINE+5]]:2 = (#0 - #1)
  // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:9 -> [[@LINE+1]]:1 = #2
 a:   // CHECK-NEXT: File 0, [[@LINE]]:1 -> [[@LINE+3]]:2 = #2
 b:   // CHECK-NEXT: File 0, [[@LINE]]:1 -> [[@LINE+2]]:2 = #3
Index: test/CoverageMapping/deferred-region.cpp
===
--- test/CoverageMapping/deferred-region.cpp
+++ test/CoverageMapping/deferred-region.cpp
@@ -7,19 +7,20 @@
 void foo(int x) {
   if (x == 0) {
 return;
-  } // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+2]]:2 = (#0 - #1)
-
+  } // CHECK-NOT: Gap,File 0, [[@LINE]]:4
+//< Don't complete the last deferred region in a decl, even though it may
+//< leave some whitespace marked with the same counter as the final return.
 }
 
-// CHECK-NEXT: _Z4foooi:
+// CHECK-LABEL: _Z4foooi:
 void fooo(int x) {
   if (x == 0) {
 return;
   } // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+2]]:3 = (#0 - #1)
 
   if (x == 1) {
 return;
-  } // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+2]]:2 = ((#0 - #1) - #2)
+  } // CHECK-NOT: Gap,File 0, [[@LINE]]:4
 
 }
 
@@ -108,7 +109,7 @@
   }
 
   if (false)
-return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+1]]:2
+return; // CHECK-NOT: Gap,File 0, [[@LINE]]:11
 }
 
 // CHECK-LABEL: _Z8for_loopv:
@@ -167,7 +168,18 @@
   return; // CHECK: [[@LINE]]:3 -> [[@LINE+4]]:2 = (#0 - #1)
 
 out:
-	return; // CHECK: Gap,File 0, [[@LINE]]:8 -> [[@LINE+1]]:2 = 0
+	return; // CHECK-NOT: Gap,File 0, [[@LINE]]:8
+}
+
+// CHECK-LABEL: _Z8switchesv:
+void switches() {
+  int x;
+  switch (x) {
+case 0:
+  return;
+default:
+  return; // CHECK-NOT: Gap,File 0, [[@LINE]]
+  }
 }
 
 #include "deferred-region-helper.h"
Index: 

[PATCH] D46918: [Coverage] Discard the last uncompleted deferred region in a decl

2018-05-25 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D46918



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


[PATCH] D46918: [Coverage] Discard the last uncompleted deferred region in a decl

2018-05-25 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

Ping.


https://reviews.llvm.org/D46918



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


[PATCH] D46918: [Coverage] Discard the last uncompleted deferred region in a decl

2018-05-17 Thread Vedant Kumar via Phabricator via cfe-commits
vsk updated this revision to Diff 147360.
vsk added a comment.

- Add a regression test for switches.


https://reviews.llvm.org/D46918

Files:
  lib/CodeGen/CoverageMappingGen.cpp
  test/CoverageMapping/deferred-region.cpp
  test/CoverageMapping/label.cpp
  test/CoverageMapping/moremacros.c
  test/CoverageMapping/trycatch.cpp

Index: test/CoverageMapping/trycatch.cpp
===
--- test/CoverageMapping/trycatch.cpp
+++ test/CoverageMapping/trycatch.cpp
@@ -18,7 +18,7 @@
   // CHECK: File 0, [[@LINE+1]]:10 -> [[@LINE+2]]:27 = (#0 - #1)
   } else if(i == 8)   // CHECK-NEXT: File 0, [[@LINE]]:13 -> [[@LINE]]:19 = (#0 - #1)
 throw ImportantError();   // CHECK: File 0, [[@LINE]]:5 -> [[@LINE]]:27 = #2
-} // CHECK-NEXT: File 0, [[@LINE-1]]:27 -> [[@LINE]]:2 = ((#0 - #1) - #2)
+}
 
   // CHECK-NEXT: main
 int main() {  // CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+13]]:2 = #0
Index: test/CoverageMapping/moremacros.c
===
--- test/CoverageMapping/moremacros.c
+++ test/CoverageMapping/moremacros.c
@@ -31,7 +31,7 @@
   if (!argc) {
 return 0;
   // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:8 = #4
-  RBRAC // CHECK-NEXT: [[@LINE]]:8 -> [[@LINE+1]]:2 = (((#0 - #2) - #3) - #4)
+  RBRAC
 }
 
 // CHECK-NEXT: File 1, 3:15 -> 3:16 = #2
Index: test/CoverageMapping/label.cpp
===
--- test/CoverageMapping/label.cpp
+++ test/CoverageMapping/label.cpp
@@ -16,19 +16,18 @@
   goto x;// CHECK: File 0, [[@LINE]]:7 -> [[@LINE]]:13 = (#1 - #2)
 int k = 3;   // CHECK-NEXT: File 0, [[@LINE-1]]:13 -> [[@LINE]]:5 = #3
   }  // CHECK-NEXT: File 0, [[@LINE-1]]:5 -> [[@LINE]]:4 = #3
-  static int j = 0;  // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+5]]:2 = ((#0 + #3) - #1)
+  static int j = 0;  // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+4]]:2 = ((#0 + #3) - #1)
   ++j;
   if(j == 1) // CHECK-NEXT: File 0, [[@LINE]]:6 -> [[@LINE]]:12 = ((#0 + #3) - #1)
 goto x;  // CHECK: File 0, [[@LINE]]:5 -> [[@LINE]]:11 = #4
- // CHECK-NEXT: File 0, [[@LINE-1]]:11 -> [[@LINE+1]]:2 = (((#0 + #3) - #1) - #4)
 }
 
  // CHECK-NEXT: test1
 void test1(int x) {  // CHECK-NEXT: File 0, [[@LINE]]:19 -> {{[0-9]+}}:2 = #0
   if(x == 0) // CHECK-NEXT: File 0, [[@LINE]]:6 -> [[@LINE]]:12 = #0
 goto a;  // CHECK: File 0, [[@LINE]]:5 -> [[@LINE]]:11 = #1
  // CHECK-NEXT: File 0, [[@LINE-1]]:11 -> [[@LINE+1]]:3 = (#0 - #1)
-  goto b;// CHECK: Gap,File 0, [[@LINE]]:3 -> [[@LINE+5]]:2 = #3
+  goto b;// CHECK: File 0, [[@LINE]]:3 -> [[@LINE+5]]:2 = (#0 - #1)
  // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:9 -> [[@LINE+1]]:1 = #2
 a:   // CHECK-NEXT: File 0, [[@LINE]]:1 -> [[@LINE+3]]:2 = #2
 b:   // CHECK-NEXT: File 0, [[@LINE]]:1 -> [[@LINE+2]]:2 = #3
Index: test/CoverageMapping/deferred-region.cpp
===
--- test/CoverageMapping/deferred-region.cpp
+++ test/CoverageMapping/deferred-region.cpp
@@ -7,19 +7,20 @@
 void foo(int x) {
   if (x == 0) {
 return;
-  } // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+2]]:2 = (#0 - #1)
-
+  } // CHECK-NOT: Gap,File 0, [[@LINE]]:4
+//< Don't complete the last deferred region in a decl, even though it may
+//< leave some whitespace marked with the same counter as the final return.
 }
 
-// CHECK-NEXT: _Z4foooi:
+// CHECK-LABEL: _Z4foooi:
 void fooo(int x) {
   if (x == 0) {
 return;
   } // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+2]]:3 = (#0 - #1)
 
   if (x == 1) {
 return;
-  } // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+2]]:2 = ((#0 - #1) - #2)
+  } // CHECK-NOT: Gap,File 0, [[@LINE]]:4
 
 }
 
@@ -108,7 +109,7 @@
   }
 
   if (false)
-return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+1]]:2
+return; // CHECK-NOT: Gap,File 0, [[@LINE]]:11
 }
 
 // CHECK-LABEL: _Z8for_loopv:
@@ -167,7 +168,18 @@
   return; // CHECK: [[@LINE]]:3 -> [[@LINE+4]]:2 = (#0 - #1)
 
 out:
-	return; // CHECK: Gap,File 0, [[@LINE]]:8 -> [[@LINE+1]]:2 = 0
+	return; // CHECK-NOT: Gap,File 0, [[@LINE]]:8
+}
+
+// CHECK-LABEL: _Z8switchesv:
+void switches() {
+  int x;
+  switch (x) {
+case 0:
+  return;
+default:
+  return; // CHECK-NOT: Gap,File 0, [[@LINE]]
+  }
 }
 
 #include "deferred-region-helper.h"
Index: lib/CodeGen/CoverageMappingGen.cpp
===
--- lib/CodeGen/CoverageMappingGen.cpp

[PATCH] D46918: [Coverage] Discard the last uncompleted deferred region in a decl

2018-05-15 Thread Vedant Kumar via Phabricator via cfe-commits
vsk created this revision.
vsk added a reviewer: arphaman.

Discard the last uncompleted deferred region in a decl, if one exists.
This prevents lines at the end of a function containing only whitespace
or closing braces from being marked as uncovered, if they follow a
region terminator (return/break/etc).

The previous behavior was to heuristically complete deferred regions at
the end of a decl. In practice this ended up being too brittle for too
little gain. Users would complain that there was no way to reach full
code coverage because whitespace at the end of a function would be
marked uncovered.

rdar://40238228


https://reviews.llvm.org/D46918

Files:
  lib/CodeGen/CoverageMappingGen.cpp
  test/CoverageMapping/deferred-region.cpp
  test/CoverageMapping/label.cpp
  test/CoverageMapping/moremacros.c
  test/CoverageMapping/trycatch.cpp

Index: test/CoverageMapping/trycatch.cpp
===
--- test/CoverageMapping/trycatch.cpp
+++ test/CoverageMapping/trycatch.cpp
@@ -18,7 +18,7 @@
   // CHECK: File 0, [[@LINE+1]]:10 -> [[@LINE+2]]:27 = (#0 - #1)
   } else if(i == 8)   // CHECK-NEXT: File 0, [[@LINE]]:13 -> [[@LINE]]:19 = (#0 - #1)
 throw ImportantError();   // CHECK: File 0, [[@LINE]]:5 -> [[@LINE]]:27 = #2
-} // CHECK-NEXT: File 0, [[@LINE-1]]:27 -> [[@LINE]]:2 = ((#0 - #1) - #2)
+}
 
   // CHECK-NEXT: main
 int main() {  // CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+13]]:2 = #0
Index: test/CoverageMapping/moremacros.c
===
--- test/CoverageMapping/moremacros.c
+++ test/CoverageMapping/moremacros.c
@@ -31,7 +31,7 @@
   if (!argc) {
 return 0;
   // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:8 = #4
-  RBRAC // CHECK-NEXT: [[@LINE]]:8 -> [[@LINE+1]]:2 = (((#0 - #2) - #3) - #4)
+  RBRAC
 }
 
 // CHECK-NEXT: File 1, 3:15 -> 3:16 = #2
Index: test/CoverageMapping/label.cpp
===
--- test/CoverageMapping/label.cpp
+++ test/CoverageMapping/label.cpp
@@ -16,19 +16,18 @@
   goto x;// CHECK: File 0, [[@LINE]]:7 -> [[@LINE]]:13 = (#1 - #2)
 int k = 3;   // CHECK-NEXT: File 0, [[@LINE-1]]:13 -> [[@LINE]]:5 = #3
   }  // CHECK-NEXT: File 0, [[@LINE-1]]:5 -> [[@LINE]]:4 = #3
-  static int j = 0;  // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+5]]:2 = ((#0 + #3) - #1)
+  static int j = 0;  // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+4]]:2 = ((#0 + #3) - #1)
   ++j;
   if(j == 1) // CHECK-NEXT: File 0, [[@LINE]]:6 -> [[@LINE]]:12 = ((#0 + #3) - #1)
 goto x;  // CHECK: File 0, [[@LINE]]:5 -> [[@LINE]]:11 = #4
- // CHECK-NEXT: File 0, [[@LINE-1]]:11 -> [[@LINE+1]]:2 = (((#0 + #3) - #1) - #4)
 }
 
  // CHECK-NEXT: test1
 void test1(int x) {  // CHECK-NEXT: File 0, [[@LINE]]:19 -> {{[0-9]+}}:2 = #0
   if(x == 0) // CHECK-NEXT: File 0, [[@LINE]]:6 -> [[@LINE]]:12 = #0
 goto a;  // CHECK: File 0, [[@LINE]]:5 -> [[@LINE]]:11 = #1
  // CHECK-NEXT: File 0, [[@LINE-1]]:11 -> [[@LINE+1]]:3 = (#0 - #1)
-  goto b;// CHECK: Gap,File 0, [[@LINE]]:3 -> [[@LINE+5]]:2 = #3
+  goto b;// CHECK: File 0, [[@LINE]]:3 -> [[@LINE+5]]:2 = (#0 - #1)
  // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:9 -> [[@LINE+1]]:1 = #2
 a:   // CHECK-NEXT: File 0, [[@LINE]]:1 -> [[@LINE+3]]:2 = #2
 b:   // CHECK-NEXT: File 0, [[@LINE]]:1 -> [[@LINE+2]]:2 = #3
Index: test/CoverageMapping/deferred-region.cpp
===
--- test/CoverageMapping/deferred-region.cpp
+++ test/CoverageMapping/deferred-region.cpp
@@ -7,19 +7,20 @@
 void foo(int x) {
   if (x == 0) {
 return;
-  } // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+2]]:2 = (#0 - #1)
-
+  } // CHECK-NOT: Gap,File 0, [[@LINE]]:4
+//< Don't complete the last deferred region in a decl, even though it may
+//< leave some whitespace marked with the same counter as the final return.
 }
 
-// CHECK-NEXT: _Z4foooi:
+// CHECK-LABEL: _Z4foooi:
 void fooo(int x) {
   if (x == 0) {
 return;
   } // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+2]]:3 = (#0 - #1)
 
   if (x == 1) {
 return;
-  } // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+2]]:2 = ((#0 - #1) - #2)
+  } // CHECK-NOT: Gap,File 0, [[@LINE]]:4
 
 }
 
@@ -108,7 +109,7 @@
   }
 
   if (false)
-return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+1]]:2
+return; // CHECK-NOT: Gap,File 0, [[@LINE]]:11
 }
 
 // CHECK-LABEL: _Z8for_loopv:
@@ -167,7 +168,7 @@
   return; // CHECK: