[cfe-commits] r152956 - in /cfe/trunk: lib/CodeGen/CodeGenAction.cpp test/Frontend/ir-support-errors.ll
Benjamin Kramer
benny.kra at googlemail.com
Fri Mar 16 15:31:42 PDT 2012
Author: d0k
Date: Fri Mar 16 17:31:42 2012
New Revision: 152956
URL: http://llvm.org/viewvc/llvm-project?rev=152956&view=rev
Log:
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 %.
Modified:
cfe/trunk/lib/CodeGen/CodeGenAction.cpp
cfe/trunk/test/Frontend/ir-support-errors.ll
Modified: cfe/trunk/lib/CodeGen/CodeGenAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenAction.cpp?rev=152956&r1=152955&r2=152956&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenAction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp Fri Mar 16 17:31:42 2012
@@ -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 @@
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;
Modified: cfe/trunk/test/Frontend/ir-support-errors.ll
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/ir-support-errors.ll?rev=152956&r1=152955&r2=152956&view=diff
==============================================================================
--- cfe/trunk/test/Frontend/ir-support-errors.ll (original)
+++ cfe/trunk/test/Frontend/ir-support-errors.ll Fri Mar 16 17:31:42 2012
@@ -3,6 +3,6 @@
target triple = "x86_64-apple-darwin10"
define i32 @f0() nounwind ssp {
-; CHECK: {{.*}}ir-support-errors.ll:7:16: error: expected value token
- ret i32 x
+; CHECK: {{.*}}ir-support-errors.ll:7:16: error: use of undefined value '%x'
+ ret i32 %x
}
More information about the cfe-commits
mailing list