diff options
author | dim <dim@FreeBSD.org> | 2013-04-08 18:45:10 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2013-04-08 18:45:10 +0000 |
commit | c72c57c9e9b69944e3e009cd5e209634839581d3 (patch) | |
tree | 4fc2f184c499d106f29a386c452b49e5197bf63d /lib/Frontend/TextDiagnosticBuffer.cpp | |
parent | 5b20025c30d23d521e12c1f33ec8fa6b821952cd (diff) | |
download | FreeBSD-src-c72c57c9e9b69944e3e009cd5e209634839581d3.zip FreeBSD-src-c72c57c9e9b69944e3e009cd5e209634839581d3.tar.gz |
Vendor import of clang trunk r178860:
http://llvm.org/svn/llvm-project/cfe/trunk@178860
Diffstat (limited to 'lib/Frontend/TextDiagnosticBuffer.cpp')
-rw-r--r-- | lib/Frontend/TextDiagnosticBuffer.cpp | 26 |
1 files changed, 23 insertions, 3 deletions
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<char> &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<char, 64> 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 { |