@@ -237,34 +237,19 @@ verifyUnknown(SourceManager &SM,
237237}
238238} // end anonymous namespace
239239
240- static unsigned getColumnNumber (StringRef buffer, llvm::SMLoc loc) {
241- assert (loc.getPointer () >= buffer.data ());
242- assert ((size_t )(loc.getPointer () - buffer.data ()) <= buffer.size ());
243-
244- StringRef UpToLoc = buffer.slice (0 , loc.getPointer () - buffer.data ());
245-
246- size_t ColumnNo = UpToLoc.size ();
247- size_t NewlinePos = UpToLoc.find_last_of (" \r\n " );
248- if (NewlinePos != StringRef::npos)
249- ColumnNo -= NewlinePos;
250-
251- return static_cast <unsigned >(ColumnNo);
252- }
253-
254240// / Return true if the given \p ExpectedFixIt is in the fix-its emitted by
255241// / diagnostic \p D.
256242bool DiagnosticVerifier::checkForFixIt (const ExpectedFixIt &Expected,
257243 const CapturedDiagnosticInfo &D,
258- StringRef buffer) {
244+ unsigned BufferID) const {
259245 for (auto &ActualFixIt : D.FixIts ) {
260246 if (ActualFixIt.getText () != Expected.Text )
261247 continue ;
262248
263249 CharSourceRange Range = ActualFixIt.getRange ();
264- if (getColumnNumber (buffer, getRawLoc (Range.getStart ())) !=
265- Expected.StartCol )
250+ if (SM.getColumnInBuffer (Range.getStart (), BufferID) != Expected.StartCol )
266251 continue ;
267- if (getColumnNumber (buffer, getRawLoc ( Range.getEnd ()) ) != Expected.EndCol )
252+ if (SM. getColumnInBuffer ( Range.getEnd (), BufferID ) != Expected.EndCol )
268253 continue ;
269254
270255 return true ;
@@ -275,17 +260,17 @@ bool DiagnosticVerifier::checkForFixIt(const ExpectedFixIt &Expected,
275260
276261std::string
277262DiagnosticVerifier::renderFixits (ArrayRef<DiagnosticInfo::FixIt> fixits,
278- StringRef InputFile) {
263+ unsigned BufferID) const {
279264 std::string Result;
280265 llvm::raw_string_ostream OS (Result);
281266 interleave (fixits,
282267 [&](const DiagnosticInfo::FixIt &ActualFixIt) {
283268 CharSourceRange Range = ActualFixIt.getRange ();
284269
285270 OS << " {{"
286- << getColumnNumber (InputFile, getRawLoc ( Range.getStart ()) )
271+ << SM. getColumnInBuffer ( Range.getStart (), BufferID )
287272 << ' -'
288- << getColumnNumber (InputFile, getRawLoc ( Range.getEnd ()) )
273+ << SM. getColumnInBuffer ( Range.getEnd (), BufferID )
289274 << ' =' ;
290275
291276 for (auto C : ActualFixIt.getText ()) {
@@ -627,7 +612,7 @@ DiagnosticVerifier::Result DiagnosticVerifier::verifyFile(unsigned BufferID) {
627612 // Verify that any expected fix-its are present in the diagnostic.
628613 for (auto fixit : expected.Fixits ) {
629614 // If we found it, we're ok.
630- if (!checkForFixIt (fixit, FoundDiagnostic, InputFile )) {
615+ if (!checkForFixIt (fixit, FoundDiagnostic, BufferID )) {
631616 missedFixitLoc = fixit.StartLoc ;
632617 break ;
633618 }
@@ -644,7 +629,7 @@ DiagnosticVerifier::Result DiagnosticVerifier::verifyFile(unsigned BufferID) {
644629 auto makeActualFixitsPhrase =
645630 [&](ArrayRef<DiagnosticInfo::FixIt> actualFixits)
646631 -> ActualFixitsPhrase {
647- std::string actualFixitsStr = renderFixits (actualFixits, InputFile );
632+ std::string actualFixitsStr = renderFixits (actualFixits, BufferID );
648633
649634 return ActualFixitsPhrase{(Twine (" actual fix-it" ) +
650635 (actualFixits.size () >= 2 ? " s" : " " ) +
0 commit comments