r317760 - [Coverage] Emit deferred regions in headers
Vedant Kumar via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 8 18:33:40 PST 2017
Author: vedantk
Date: Wed Nov 8 18:33:40 2017
New Revision: 317760
URL: http://llvm.org/viewvc/llvm-project?rev=317760&view=rev
Log:
[Coverage] Emit deferred regions in headers
There are some limitations with emitting regions in macro expansions
because we don't gather file IDs within the expansions. Fix the check
that prevents us from emitting deferred regions in expansions to make an
exception for headers, which is something we can handle.
rdar://35373009
Added:
cfe/trunk/test/CoverageMapping/Inputs/deferred-region-helper.h
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=317760&r1=317759&r2=317760&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp (original)
+++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp Wed Nov 8 18:33:40 2017
@@ -496,12 +496,14 @@ struct CounterCoverageMappingBuilder
DeferredRegion = None;
// If the region ends in an expansion, find the expansion site.
- if (SM.getFileID(DeferredEndLoc) != SM.getMainFileID()) {
- FileID StartFile = SM.getFileID(DR.getStartLoc());
+ FileID StartFile = SM.getFileID(DR.getStartLoc());
+ if (SM.getFileID(DeferredEndLoc) != StartFile) {
if (isNestedIn(DeferredEndLoc, StartFile)) {
do {
DeferredEndLoc = getIncludeOrExpansionLoc(DeferredEndLoc);
} while (StartFile != SM.getFileID(DeferredEndLoc));
+ } else {
+ return Index;
}
}
@@ -591,7 +593,7 @@ struct CounterCoverageMappingBuilder
if (!DeferredRegion.hasValue() &&
// File IDs aren't gathered within macro expansions, so it isn't
// useful to try and create a deferred region inside of one.
- (SM.getFileID(EndLoc) == SM.getMainFileID()))
+ !EndLoc.isMacroID())
DeferredRegion =
SourceMappingRegion(Counter::getZero(), EndLoc, None);
}
Added: cfe/trunk/test/CoverageMapping/Inputs/deferred-region-helper.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/Inputs/deferred-region-helper.h?rev=317760&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/Inputs/deferred-region-helper.h (added)
+++ cfe/trunk/test/CoverageMapping/Inputs/deferred-region-helper.h Wed Nov 8 18:33:40 2017
@@ -0,0 +1,5 @@
+void included_func() {
+ if (false)
+ return;
+ return;
+}
Modified: cfe/trunk/test/CoverageMapping/deferred-region.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/deferred-region.cpp?rev=317760&r1=317759&r2=317760&view=diff
==============================================================================
--- cfe/trunk/test/CoverageMapping/deferred-region.cpp (original)
+++ cfe/trunk/test/CoverageMapping/deferred-region.cpp Wed Nov 8 18:33:40 2017
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++11 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -fexceptions -fcxx-exceptions -emit-llvm-only -triple %itanium_abi_triple -main-file-name deferred-region.cpp %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -fexceptions -fcxx-exceptions -emit-llvm-only -triple %itanium_abi_triple -main-file-name deferred-region.cpp -I %S/Inputs %s | FileCheck %s
#define IF if
#define STMT(S) S
@@ -170,6 +170,16 @@ out:
return; // CHECK: Gap,File 0, [[@LINE]]:8 -> [[@LINE+1]]:2 = 0
}
+#include "deferred-region-helper.h"
+// CHECK-LABEL: _Z13included_funcv:
+// CHECK: Gap,File 0, 2:13 -> 3:5 = #1
+// CHECK: Gap,File 0, 3:11 -> 4:3 = (#0 - #1)
+
+// CHECK-LABEL: _Z7includev:
+void include() {
+ included_func();
+}
+
int main() {
foo(0);
foo(1);
@@ -189,5 +199,6 @@ int main() {
for_loop();
while_loop();
gotos();
+ include();
return 0;
}
More information about the cfe-commits
mailing list