This revision was automatically updated to reflect the committed changes. Closed by commit rL279962: [Coverage] Prevent creating a redundant counter if a nested body ends with a… (authored by ikudrin).
Changed prior to commit: https://reviews.llvm.org/D23160?vs=66790&id=69556#toc Repository: rL LLVM https://reviews.llvm.org/D23160 Files: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp cfe/trunk/test/CoverageMapping/macros.c Index: cfe/trunk/test/CoverageMapping/macros.c =================================================================== --- cfe/trunk/test/CoverageMapping/macros.c +++ cfe/trunk/test/CoverageMapping/macros.c @@ -36,8 +36,20 @@ // CHECK-NEXT: File 1, 4:17 -> 4:22 = #0 // CHECK-NEXT: File 2, 4:17 -> 4:22 = #0 +// CHECK-NEXT: func4 +void func4() { // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE+6]]:2 = #0 + int i = 0; + while (i++ < 10) // CHECK-NEXT: File 0, [[@LINE]]:10 -> [[@LINE]]:18 = (#0 + #1) + if (i < 5) // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE+2]]:14 = #1 + // CHECK-NEXT: File 0, [[@LINE-1]]:9 -> [[@LINE-1]]:14 = #1 + MACRO_2; // CHECK-NEXT: Expansion,File 0, [[@LINE]]:7 -> [[@LINE]]:14 = #2 +} +// CHECK-NEXT: File 1, 4:17 -> 4:22 = #2 +// CHECK-NOT: File 1 + int main(int argc, const char *argv[]) { func(); func2(); func3(); + func4(); } Index: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp =================================================================== --- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp +++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp @@ -432,7 +432,8 @@ SourceLocation NestedLoc = getStartOfFileOrMacro(EndLoc); assert(SM.isWrittenInSameFile(NestedLoc, EndLoc)); - SourceRegions.emplace_back(Region.getCounter(), NestedLoc, EndLoc); + if (!isRegionAlreadyAdded(NestedLoc, EndLoc)) + SourceRegions.emplace_back(Region.getCounter(), NestedLoc, EndLoc); EndLoc = getPreciseTokenLocEnd(getIncludeOrExpansionLoc(EndLoc)); if (EndLoc.isInvalid())
Index: cfe/trunk/test/CoverageMapping/macros.c =================================================================== --- cfe/trunk/test/CoverageMapping/macros.c +++ cfe/trunk/test/CoverageMapping/macros.c @@ -36,8 +36,20 @@ // CHECK-NEXT: File 1, 4:17 -> 4:22 = #0 // CHECK-NEXT: File 2, 4:17 -> 4:22 = #0 +// CHECK-NEXT: func4 +void func4() { // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE+6]]:2 = #0 + int i = 0; + while (i++ < 10) // CHECK-NEXT: File 0, [[@LINE]]:10 -> [[@LINE]]:18 = (#0 + #1) + if (i < 5) // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE+2]]:14 = #1 + // CHECK-NEXT: File 0, [[@LINE-1]]:9 -> [[@LINE-1]]:14 = #1 + MACRO_2; // CHECK-NEXT: Expansion,File 0, [[@LINE]]:7 -> [[@LINE]]:14 = #2 +} +// CHECK-NEXT: File 1, 4:17 -> 4:22 = #2 +// CHECK-NOT: File 1 + int main(int argc, const char *argv[]) { func(); func2(); func3(); + func4(); } Index: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp =================================================================== --- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp +++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp @@ -432,7 +432,8 @@ SourceLocation NestedLoc = getStartOfFileOrMacro(EndLoc); assert(SM.isWrittenInSameFile(NestedLoc, EndLoc)); - SourceRegions.emplace_back(Region.getCounter(), NestedLoc, EndLoc); + if (!isRegionAlreadyAdded(NestedLoc, EndLoc)) + SourceRegions.emplace_back(Region.getCounter(), NestedLoc, EndLoc); EndLoc = getPreciseTokenLocEnd(getIncludeOrExpansionLoc(EndLoc)); if (EndLoc.isInvalid())
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits