From c72c57c9e9b69944e3e009cd5e209634839581d3 Mon Sep 17 00:00:00 2001 From: dim Date: Mon, 8 Apr 2013 18:45:10 +0000 Subject: Vendor import of clang trunk r178860: http://llvm.org/svn/llvm-project/cfe/trunk@178860 --- lib/Frontend/TextDiagnosticBuffer.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'lib/Frontend/TextDiagnosticBuffer.cpp') diff --git a/lib/Frontend/TextDiagnosticBuffer.cpp b/lib/Frontend/TextDiagnosticBuffer.cpp index 57105f1..039475a 100644 --- a/lib/Frontend/TextDiagnosticBuffer.cpp +++ b/lib/Frontend/TextDiagnosticBuffer.cpp @@ -42,17 +42,37 @@ void TextDiagnosticBuffer::HandleDiagnostic(DiagnosticsEngine::Level Level, } } +/// \brief Escape diagnostic texts to avoid problems when they are fed into the +/// diagnostic formatter a second time. +static StringRef escapeDiag(StringRef Str, SmallVectorImpl &Buf) { + size_t Pos = Str.find('%'); + if (Pos == StringRef::npos) + return Str; + + // We found a '%'. Replace this and all following '%' with '%%'. + Buf.clear(); + Buf.append(Str.data(), Str.data() + Pos); + for (size_t I = Pos, E = Str.size(); I != E; ++I) { + if (Str[I] == '%') + Buf.push_back('%'); + Buf.push_back(Str[I]); + } + + return StringRef(Buf.data(), Buf.size()); +} + void TextDiagnosticBuffer::FlushDiagnostics(DiagnosticsEngine &Diags) const { + SmallVector Buf; // FIXME: Flush the diagnostics in order. for (const_iterator it = err_begin(), ie = err_end(); it != ie; ++it) Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Error, - it->second.c_str())); + escapeDiag(it->second, Buf))); for (const_iterator it = warn_begin(), ie = warn_end(); it != ie; ++it) Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Warning, - it->second.c_str())); + escapeDiag(it->second, Buf))); for (const_iterator it = note_begin(), ie = note_end(); it != ie; ++it) Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Note, - it->second.c_str())); + escapeDiag(it->second, Buf))); } DiagnosticConsumer *TextDiagnosticBuffer::clone(DiagnosticsEngine &) const { -- cgit v1.1