Escape % in the TextDiagnosticBuffer so they aren't interpreted twice when fed into the diagnostic formatting machinery again.

Fixes PR14543.

llvm-svn: 169677
This commit is contained in:
Benjamin Kramer 2012-12-08 12:42:30 +00:00
parent f242d8c31b
commit 2fec65d394
2 changed files with 26 additions and 4 deletions

View File

@ -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 {

View File

@ -1,4 +1,6 @@
// RUN: not %clang_cc1 %s -cake-is-lie 2> %t.log
// RUN: not %clang_cc1 %s -cake-is-lie -%0 -%d 2> %t.log
// RUN: FileCheck %s -input-file=%t.log
// CHECK: unknown argument
// CHECK: unknown argument
// CHECK: unknown argument