[llvm-branch-commits] [cfe-branch] r347798 - Merging r347262:
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Nov 28 12:04:13 PST 2018
Author: tstellar
Date: Wed Nov 28 12:04:13 2018
New Revision: 347798
URL: http://llvm.org/viewvc/llvm-project?rev=347798&view=rev
Log:
Merging r347262:
------------------------------------------------------------------------
r347262 | vedantk | 2018-11-19 12:10:22 -0800 (Mon, 19 Nov 2018) | 8 lines
[Coverage] Fix PR39258: support coverage regions that start deeper than they end
popRegions used to assume that the start location of a region can't be
nested deeper than the end location, which is not always true.
Patch by Orivej Desh!
Differential Revision: https://reviews.llvm.org/D53244
------------------------------------------------------------------------
Modified:
cfe/branches/release_70/lib/CodeGen/CoverageMappingGen.cpp
cfe/branches/release_70/test/CoverageMapping/macros.c
Modified: cfe/branches/release_70/lib/CodeGen/CoverageMappingGen.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_70/lib/CodeGen/CoverageMappingGen.cpp?rev=347798&r1=347797&r2=347798&view=diff
==============================================================================
--- cfe/branches/release_70/lib/CodeGen/CoverageMappingGen.cpp (original)
+++ cfe/branches/release_70/lib/CodeGen/CoverageMappingGen.cpp Wed Nov 28 12:04:13 2018
@@ -553,6 +553,15 @@ struct CounterCoverageMappingBuilder
completeDeferred(Count, DeferredEndLoc);
}
+ size_t locationDepth(SourceLocation Loc) {
+ size_t Depth = 0;
+ while (Loc.isValid()) {
+ Loc = getIncludeOrExpansionLoc(Loc);
+ Depth++;
+ }
+ return Depth;
+ }
+
/// Pop regions from the stack into the function's list of regions.
///
/// Adds all regions from \c ParentIndex to the top of the stack to the
@@ -567,19 +576,41 @@ struct CounterCoverageMappingBuilder
SourceLocation EndLoc = Region.hasEndLoc()
? Region.getEndLoc()
: RegionStack[ParentIndex].getEndLoc();
+ size_t StartDepth = locationDepth(StartLoc);
+ size_t EndDepth = locationDepth(EndLoc);
while (!SM.isWrittenInSameFile(StartLoc, EndLoc)) {
- // The region ends in a nested file or macro expansion. Create a
- // separate region for each expansion.
- SourceLocation NestedLoc = getStartOfFileOrMacro(EndLoc);
- assert(SM.isWrittenInSameFile(NestedLoc, EndLoc));
-
- if (!isRegionAlreadyAdded(NestedLoc, EndLoc))
- SourceRegions.emplace_back(Region.getCounter(), NestedLoc, EndLoc);
-
- EndLoc = getPreciseTokenLocEnd(getIncludeOrExpansionLoc(EndLoc));
- if (EndLoc.isInvalid())
- llvm::report_fatal_error("File exit not handled before popRegions");
+ bool UnnestStart = StartDepth >= EndDepth;
+ bool UnnestEnd = EndDepth >= StartDepth;
+ if (UnnestEnd) {
+ // The region ends in a nested file or macro expansion. Create a
+ // separate region for each expansion.
+ SourceLocation NestedLoc = getStartOfFileOrMacro(EndLoc);
+ assert(SM.isWrittenInSameFile(NestedLoc, EndLoc));
+
+ if (!isRegionAlreadyAdded(NestedLoc, EndLoc))
+ SourceRegions.emplace_back(Region.getCounter(), NestedLoc, EndLoc);
+
+ EndLoc = getPreciseTokenLocEnd(getIncludeOrExpansionLoc(EndLoc));
+ if (EndLoc.isInvalid())
+ llvm::report_fatal_error("File exit not handled before popRegions");
+ EndDepth--;
+ }
+ if (UnnestStart) {
+ // The region begins in a nested file or macro expansion. Create a
+ // separate region for each expansion.
+ SourceLocation NestedLoc = getEndOfFileOrMacro(StartLoc);
+ assert(SM.isWrittenInSameFile(StartLoc, NestedLoc));
+
+ if (!isRegionAlreadyAdded(StartLoc, NestedLoc))
+ SourceRegions.emplace_back(Region.getCounter(), StartLoc, NestedLoc);
+
+ StartLoc = getIncludeOrExpansionLoc(StartLoc);
+ if (StartLoc.isInvalid())
+ llvm::report_fatal_error("File exit not handled before popRegions");
+ StartDepth--;
+ }
}
+ Region.setStartLoc(StartLoc);
Region.setEndLoc(EndLoc);
MostRecentLocation = EndLoc;
Modified: cfe/branches/release_70/test/CoverageMapping/macros.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_70/test/CoverageMapping/macros.c?rev=347798&r1=347797&r2=347798&view=diff
==============================================================================
--- cfe/branches/release_70/test/CoverageMapping/macros.c (original)
+++ cfe/branches/release_70/test/CoverageMapping/macros.c Wed Nov 28 12:04:13 2018
@@ -4,6 +4,7 @@
#define MACRO_2 bar()
#define MACRO_1 return; MACRO_2
#define MACRO_3 MACRO_2
+#define GOTO goto
void bar() {}
@@ -56,6 +57,15 @@ void func5() { // CHECK-NEXT: File 0, [[
// CHECK-NEXT: Expansion,File 1, 6:17 -> 6:24 = #1
// CHECK-NEXT: File 2, 4:17 -> 4:22 = #1
+// CHECK-NEXT: func6
+void func6(unsigned count) { // CHECK-NEXT: File 0, [[@LINE]]:28 -> [[@LINE+4]]:2 = #0
+begin: // CHECK-NEXT: File 0, [[@LINE]]:1 -> [[@LINE+3]]:2 = #1
+ if (count--) // CHECK-NEXT: File 0, [[@LINE]]:9 -> [[@LINE]]:16 = #1
+ GOTO begin; // CHECK-NEXT: File 0, [[@LINE]]:9 -> [[@LINE]]:19 = #2
+}
+// CHECK-NEXT: Expansion,File 0, [[@LINE-2]]:9 -> [[@LINE-2]]:13 = #2
+// CHECK-NEXT: File 1, 7:14 -> 7:18 = #2
+
int main(int argc, const char *argv[]) {
func();
func2();
More information about the llvm-branch-commits
mailing list