[Coverage] Remove deferred region for trailing return, fixes PR34611

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.

llvm-svn: 313603
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 943c7e0..8f6f3ed 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -770,7 +770,13 @@
     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)));
   }