Fix getCustomDiagID() usage in CodeGen and TextDiagnosticBuffer

DiagIDs are a cached resource generally only constructed from compile-time
constant or stable format strings.

Escaping arbitrary messages and constructing DiagIDs from them didn't make
sense.

llvm-svn: 197856
This commit is contained in:
Alp Toker
2013-12-21 05:20:03 +00:00
parent 9477f9e52f
commit bc043f27f4
2 changed files with 13 additions and 39 deletions

View File

@@ -399,24 +399,15 @@ void CodeGenAction::ExecuteAction() {
SM.getFileEntryForID(SM.getMainFileID()), Err.getLineNo(),
Err.getColumnNo() + 1);
// Get a custom diagnostic for the error. We strip off a leading
// diagnostic code if there is one.
// Strip off a leading diagnostic code if there is one.
StringRef Msg = Err.getMessage();
if (Msg.startswith("error: "))
Msg = Msg.substr(7);
// Escape '%', which is interpreted as a format character.
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, "%0");
unsigned DiagID = CI.getDiagnostics().getCustomDiagID(
DiagnosticsEngine::Error, EscapedMessage);
CI.getDiagnostics().Report(Loc, DiagID);
CI.getDiagnostics().Report(Loc, DiagID) << Msg;
return;
}
const TargetOptions &TargetOpts = CI.getTargetOpts();