]> granicus.if.org Git - clang/commitdiff
Teach BugReporter to "escape" the occurance of '%' characters in diagnostic messages...
authorTed Kremenek <kremenek@apple.com>
Fri, 15 Jan 2010 07:56:51 +0000 (07:56 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 15 Jan 2010 07:56:51 +0000 (07:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93507 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/BugReporter.cpp
test/Analysis/misc-ps.m

index 13b7f4510d474068b6df2d05391e9daa1c3759f3..2a9531df60f18f9f58ab541bcc67472543e229a0 100644 (file)
@@ -1818,8 +1818,23 @@ void BugReporter::FlushReport(BugReportEquivClass& EQ) {
   R->getRanges(Beg, End);
   Diagnostic& Diag = getDiagnostic();
   FullSourceLoc L(R->getLocation(), getSourceManager());
-  unsigned ErrorDiag = Diag.getCustomDiagID(Diagnostic::Warning,
-                                            R->getShortDescription());
+  
+  // Search the description for '%', as that will be interpretted as a
+  // format character by FormatDiagnostics.
+  llvm::StringRef desc = R->getShortDescription();
+  unsigned ErrorDiag;
+  {
+    llvm::SmallString<512> TmpStr;
+    llvm::raw_svector_ostream Out(TmpStr);
+    for (llvm::StringRef::iterator I=desc.begin(), E=desc.end(); I!=E; ++I)
+      if (*I == '%')
+        Out << "%%";
+      else
+        Out << *I;
+    
+    Out.flush();
+    ErrorDiag = Diag.getCustomDiagID(Diagnostic::Warning, TmpStr);
+  }        
 
   switch (End-Beg) {
     default: assert(0 && "Don't handle this many ranges yet!");
index 149be03ac26d230f06e32d5b4ffc6c7e3e406ddd..9543a98fe3230cea5e15483d689fec307833e5e7 100644 (file)
@@ -801,3 +801,13 @@ void test_bad_msg(TestBadArg *p) {
   [p testBadArg:y]; // expected-warning{{Pass-by-value argument in message expression is undefined}}
 }
 
+//===----------------------------------------------------------------------===//
+// PR 6033 - Test emitting the correct output in a warning where we use '%'
+//  with operands that are undefined.
+//===----------------------------------------------------------------------===//
+
+int pr6033(int x) {
+  int y;
+  return x % y; // expected-warning{{The right operand of '%' is a garbage value}}
+}
+