1717#include " llvm/Support/ConvertUTF.h"
1818#include " llvm/Support/ErrorHandling.h"
1919#include " llvm/Support/Locale.h"
20- #include " llvm/Support/raw_ostream.h"
2120#include < algorithm>
2221#include < optional>
2322
@@ -662,7 +661,7 @@ void TextDiagnostic::emitDiagnosticMessage(
662661 FullSourceLoc Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level,
663662 StringRef Message, ArrayRef<clang::CharSourceRange> Ranges,
664663 DiagOrStoredDiag D) {
665- uint64_t StartOfLocationInfo = OS.tell ();
664+ uint64_t StartOfLocationInfo = OS.getColumn ();
666665
667666 // Emit the location of this particular diagnostic.
668667 if (Loc.isValid ())
@@ -675,8 +674,11 @@ void TextDiagnostic::emitDiagnosticMessage(
675674 printDiagnosticLevel (OS, Level, DiagOpts.ShowColors );
676675 printDiagnosticMessage (OS,
677676 /* IsSupplemental*/ Level == DiagnosticsEngine::Note,
678- Message, OS.tell () - StartOfLocationInfo,
677+ Message, OS.getColumn () - StartOfLocationInfo,
679678 DiagOpts.MessageLength , DiagOpts.ShowColors );
679+ // We use a formatted ostream, which does its own buffering. Flush here
680+ // so we keek the proper order of output.
681+ OS.flush ();
680682}
681683
682684/* static*/ void
@@ -688,11 +690,21 @@ TextDiagnostic::printDiagnosticLevel(raw_ostream &OS,
688690 switch (Level) {
689691 case DiagnosticsEngine::Ignored:
690692 llvm_unreachable (" Invalid diagnostic type" );
691- case DiagnosticsEngine::Note: OS.changeColor (noteColor, true ); break ;
692- case DiagnosticsEngine::Remark: OS.changeColor (remarkColor, true ); break ;
693- case DiagnosticsEngine::Warning: OS.changeColor (warningColor, true ); break ;
694- case DiagnosticsEngine::Error: OS.changeColor (errorColor, true ); break ;
695- case DiagnosticsEngine::Fatal: OS.changeColor (fatalColor, true ); break ;
693+ case DiagnosticsEngine::Note:
694+ OS.changeColor (noteColor, true );
695+ break ;
696+ case DiagnosticsEngine::Remark:
697+ OS.changeColor (remarkColor, true );
698+ break ;
699+ case DiagnosticsEngine::Warning:
700+ OS.changeColor (warningColor, true );
701+ break ;
702+ case DiagnosticsEngine::Error:
703+ OS.changeColor (errorColor, true );
704+ break ;
705+ case DiagnosticsEngine::Fatal:
706+ OS.changeColor (fatalColor, true );
707+ break ;
696708 }
697709 }
698710
@@ -1485,7 +1497,7 @@ void TextDiagnostic::emitSnippet(StringRef SourceLine,
14851497 if (CharStyle != Styles.end ()) {
14861498 if (!CurrentColor ||
14871499 (CurrentColor && *CurrentColor != CharStyle->Color )) {
1488- OS.changeColor (CharStyle->Color , false );
1500+ OS.changeColor (CharStyle->Color );
14891501 CurrentColor = CharStyle->Color ;
14901502 }
14911503 } else if (CurrentColor) {
0 commit comments