]> granicus.if.org Git - clang/commitdiff
[Coverage] Remove deferred region for trailing return, fixes PR34611
authorVedant Kumar <vsk@apple.com>
Tue, 19 Sep 2017 00:29:46 +0000 (00:29 +0000)
committerVedant Kumar <vsk@apple.com>
Tue, 19 Sep 2017 00:29:46 +0000 (00:29 +0000)
As a special case, throw away deferred regions for trailing returns.
This allows the closing curly brace to have a count, and is less
distracting.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@313603 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CoverageMappingGen.cpp
test/CoverageMapping/deferred-region.cpp

index 943c7e0ccd076eaa1394c9d7f5aee8a7a12faa97..8f6f3ed580380ea6204320bc551a9ae8fdde7826 100644 (file)
@@ -770,7 +770,13 @@ struct CounterCoverageMappingBuilder
     Counter ExitCount = propagateCounts(getRegionCounter(Body), Body);
     assert(RegionStack.empty() && "Regions entered but never exited");
 
-    // Complete any deferred regions introduced by the last statement in a decl.
+    // Special case: if the last statement is a return, throw away the
+    // deferred region. This allows the closing brace to have a count.
+    if (auto *CS = dyn_cast_or_null<CompoundStmt>(Body))
+      if (dyn_cast_or_null<ReturnStmt>(CS->body_back()))
+        DeferredRegion = None;
+
+    // Complete any deferred regions introduced by the last statement.
     popRegions(completeDeferred(ExitCount, getEnd(Body)));
   }
 
index 41b5e6be8c277f3bd5f82da1c883b0a5cf4c316a..743b635a9075d65ae9908e8d8d06a0af10258153 100644 (file)
@@ -28,6 +28,14 @@ void baz() { // CHECK: [[@LINE]]:12 -> [[@LINE+2]]:2
   return;    // CHECK-NOT: File
 }
 
+// CHECK-LABEL: _Z3mazv:
+void maz() {
+  if (true)
+    return; // CHECK: Gap,File 0, [[@LINE]]:11 -> 36:3 = (#0 - #1)
+
+  return; // CHECK-NOT: Gap
+}
+
 // CHECK-LABEL: _Z3bari:
 void bar(int x) {
   IF (x)