[clang] buildFixItInsertionLine should use Hints of the same FID and LineNo
Fix bug https://bugs.llvm.org/show_bug.cgi?id=33734
Differential Revision: https://reviews.llvm.org/D35230
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307809 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Frontend/TextDiagnostic.cpp b/lib/Frontend/TextDiagnostic.cpp
index a24d576..9643075 100644
--- a/lib/Frontend/TextDiagnostic.cpp
+++ b/lib/Frontend/TextDiagnostic.cpp
@@ -1061,7 +1061,8 @@
std::fill(CaretLine.begin()+StartColNo,CaretLine.begin()+EndColNo,'~');
}
-static std::string buildFixItInsertionLine(unsigned LineNo,
+static std::string buildFixItInsertionLine(FileID FID,
+ unsigned LineNo,
const SourceColumnMap &map,
ArrayRef<FixItHint> Hints,
const SourceManager &SM,
@@ -1078,7 +1079,8 @@
// code contains no newlines and is on the same line as the caret.
std::pair<FileID, unsigned> HintLocInfo
= SM.getDecomposedExpansionLoc(I->RemoveRange.getBegin());
- if (LineNo == SM.getLineNumber(HintLocInfo.first, HintLocInfo.second) &&
+ if (FID == HintLocInfo.first &&
+ LineNo == SM.getLineNumber(HintLocInfo.first, HintLocInfo.second) &&
StringRef(I->CodeToInsert).find_first_of("\n\r") == StringRef::npos) {
// Insert the new code into the line just below the code
// that the user wrote.
@@ -1114,9 +1116,6 @@
PrevHintEndCol =
HintCol + llvm::sys::locale::columnWidth(I->CodeToInsert);
- } else {
- FixItInsertionLine.clear();
- break;
}
}
}
@@ -1233,7 +1232,7 @@
}
std::string FixItInsertionLine = buildFixItInsertionLine(
- LineNo, sourceColMap, Hints, SM, DiagOpts.get());
+ FID, LineNo, sourceColMap, Hints, SM, DiagOpts.get());
// If the source line is too long for our terminal, select only the
// "interesting" source region within that line.