SourceLocation getEndOfFileOrMacro(SourceLocation Loc) {
if (Loc.isMacroID())
return Loc.getLocWithOffset(SM.getFileIDSize(SM.getFileID(Loc)) -
- SM.getFileOffset(Loc) - 1);
+ SM.getFileOffset(Loc));
return SM.getLocForEndOfFile(SM.getFileID(Loc));
}
SourceLocation Loc = S->getLocEnd();
while (SM.isMacroArgExpansion(Loc))
Loc = SM.getImmediateExpansionRange(Loc).first;
- return Loc;
+ return getPreciseTokenLocEnd(Loc);
}
/// \brief Find the set of files we have regions for and assign IDs
if (!CovFileID)
continue;
- SourceLocation LocEnd = getPreciseTokenLocEnd(Region.getEndLoc());
+ SourceLocation LocEnd = Region.getEndLoc();
assert(SM.isWrittenInSameFile(LocStart, LocEnd) &&
"region spans multiple files");
SourceRegions.emplace_back(Region.getCounter(), NestedLoc, EndLoc);
- EndLoc = getIncludeOrExpansionLoc(EndLoc);
+ EndLoc = getPreciseTokenLocEnd(getIncludeOrExpansionLoc(EndLoc));
assert(!EndLoc.isInvalid() &&
"File exit was not handled before popRegions");
}
--- /dev/null
+// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only %s | FileCheck %s
+
+#define x1 "" // ...
+#define x2 return 0
+// CHECK: main
+int main() { // CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+3]]:2 = #0
+ x1; // CHECK-NEXT: Expansion,File 0, [[@LINE]]:3 -> [[@LINE]]:5 = #0
+ x2; // CHECK-NEXT: Expansion,File 0, [[@LINE]]:3 -> [[@LINE]]:5 = #0
+}
+// CHECK-NEXT: File 1, 3:12 -> 3:14 = #0
+// CHECK-NEXT: File 2, 4:12 -> 4:20 = #0