r313603 - [Coverage] Remove deferred region for trailing return, fixes PR34611
Vedant Kumar via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 18 17:29:46 PDT 2017
Author: vedantk
Date: Mon Sep 18 17:29:46 2017
New Revision: 313603
URL: http://llvm.org/viewvc/llvm-project?rev=313603&view=rev
Log:
[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.
Modified:
cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
cfe/trunk/test/CoverageMapping/deferred-region.cpp
Modified: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp?rev=313603&r1=313602&r2=313603&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp (original)
+++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp Mon Sep 18 17:29:46 2017
@@ -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)));
}
Modified: cfe/trunk/test/CoverageMapping/deferred-region.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/deferred-region.cpp?rev=313603&r1=313602&r2=313603&view=diff
==============================================================================
--- cfe/trunk/test/CoverageMapping/deferred-region.cpp (original)
+++ cfe/trunk/test/CoverageMapping/deferred-region.cpp Mon Sep 18 17:29:46 2017
@@ -28,6 +28,14 @@ void baz() { // CHECK: [[@LINE]]:12 -> [
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)
More information about the cfe-commits
mailing list