diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2012-03-16 22:31:42 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2012-03-16 22:31:42 +0000 |
commit | 778b8b84b82171b830c76426412d1757dffcbd3a (patch) | |
tree | 3c6af8eae7f85603fa68b3c462752e24d3142574 /clang/lib/CodeGen/CodeGenAction.cpp | |
parent | 6e177d3155a183bf52b5eab8325f5c0326e93934 (diff) | |
download | bcm5719-llvm-778b8b84b82171b830c76426412d1757dffcbd3a.tar.gz bcm5719-llvm-778b8b84b82171b830c76426412d1757dffcbd3a.zip |
Escape % in diagnostic message when compiling LLVM IR.
% is a common character in IR so we'd crash on almost any malformed IR. The
diagnostic formatter expects a formatting directive when it sees an unescaped %.
llvm-svn: 152956
Diffstat (limited to 'clang/lib/CodeGen/CodeGenAction.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenAction.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 6a184e0ef92..dd32167b847 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -23,6 +23,7 @@ #include "llvm/Module.h" #include "llvm/Pass.h" #include "llvm/ADT/OwningPtr.h" +#include "llvm/ADT/SmallString.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/Support/IRReader.h" #include "llvm/Support/MemoryBuffer.h" @@ -393,8 +394,17 @@ void CodeGenAction::ExecuteAction() { StringRef Msg = Err.getMessage(); if (Msg.startswith("error: ")) Msg = Msg.substr(7); + + // Escape '%', which is interpreted as a format character. + llvm::SmallString<128> EscapedMessage; + for (unsigned i = 0, e = Msg.size(); i != e; ++i) { + if (Msg[i] == '%') + EscapedMessage += '%'; + EscapedMessage += Msg[i]; + } + unsigned DiagID = CI.getDiagnostics().getCustomDiagID( - DiagnosticsEngine::Error, Msg); + DiagnosticsEngine::Error, EscapedMessage); CI.getDiagnostics().Report(Loc, DiagID); return; |