[cfe-commits] r140732 - in /cfe/trunk: lib/Frontend/LogDiagnosticPrinter.cpp test/Driver/cc-log-diagnostics.c
Chad Rosier
mcrosier at apple.com
Wed Sep 28 16:05:08 PDT 2011
Author: mcrosier
Date: Wed Sep 28 18:05:07 2011
New Revision: 140732
URL: http://llvm.org/viewvc/llvm-project?rev=140732&view=rev
Log:
[driver] Add basic support for escaping XML characters in CC_LOG_DIAGNOSTICS
strings.
rdar://9696709
Modified:
cfe/trunk/lib/Frontend/LogDiagnosticPrinter.cpp
cfe/trunk/test/Driver/cc-log-diagnostics.c
Modified: cfe/trunk/lib/Frontend/LogDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/LogDiagnosticPrinter.cpp?rev=140732&r1=140731&r2=140732&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/LogDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/LogDiagnosticPrinter.cpp Wed Sep 28 18:05:07 2011
@@ -38,6 +38,21 @@
}
}
+// Escape XML characters inside the raw string.
+static void emitString(llvm::raw_svector_ostream &OS, const StringRef Raw) {
+ for (StringRef::iterator I = Raw.begin(), E = Raw.end(); I != E; ++I) {
+ char c = *I;
+ switch (c) {
+ default: OS << c; break;
+ case '&': OS << "&"; break;
+ case '<': OS << "<"; break;
+ case '>': OS << ">"; break;
+ case '\'': OS << "'"; break;
+ case '\"': OS << """; break;
+ }
+ }
+}
+
void LogDiagnosticPrinter::EndSourceFile() {
// We emit all the diagnostics in EndSourceFile. However, we don't emit any
// entry if no diagnostics were present.
@@ -55,11 +70,15 @@
OS << "<dict>\n";
if (!MainFilename.empty()) {
OS << " <key>main-file</key>\n"
- << " <string>" << MainFilename << "</string>\n";
+ << " <string>";
+ emitString(OS, MainFilename);
+ OS << "</string>\n";
}
if (!DwarfDebugFlags.empty()) {
OS << " <key>dwarf-debug-flags</key>\n"
- << " <string>" << DwarfDebugFlags << "</string>\n";
+ << " <string>";
+ emitString(OS, DwarfDebugFlags);
+ OS << "</string>\n";
}
OS << " <key>diagnostics</key>\n";
OS << " <array>\n";
@@ -68,10 +87,14 @@
OS << " <dict>\n";
OS << " <key>level</key>\n"
- << " <string>" << getLevelName(DE.DiagnosticLevel) << "</string>\n";
+ << " <string>";
+ emitString(OS, getLevelName(DE.DiagnosticLevel));
+ OS << "</string>\n";
if (!DE.Filename.empty()) {
OS << " <key>filename</key>\n"
- << " <string>" << DE.Filename << "</string>\n";
+ << " <string>";
+ emitString(OS, DE.Filename);
+ OS << "</string>\n";
}
if (DE.Line != 0) {
OS << " <key>line</key>\n"
@@ -83,7 +106,9 @@
}
if (!DE.Message.empty()) {
OS << " <key>message</key>\n"
- << " <string>" << DE.Message << "</string>\n";
+ << " <string>";
+ emitString(OS, DE.Message);
+ OS << "</string>\n";
}
OS << " </dict>\n";
}
Modified: cfe/trunk/test/Driver/cc-log-diagnostics.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cc-log-diagnostics.c?rev=140732&r1=140731&r2=140732&view=diff
==============================================================================
--- cfe/trunk/test/Driver/cc-log-diagnostics.c (original)
+++ cfe/trunk/test/Driver/cc-log-diagnostics.c Wed Sep 28 18:05:07 2011
@@ -17,7 +17,7 @@
// CHECK: <key>level</key>
// CHECK: <string>warning</string>
// CHECK: <key>message</key>
-// CHECK: <string>unknown warning option '-Wfoobar'</string>
+// CHECK: <string>unknown warning option '-Wfoobar'</string>
// CHECK: </dict>
// CHECK: <dict>
// CHECK: <key>level</key>
More information about the cfe-commits
mailing list