[llvm-commits] [llvm] r172164 - /llvm/trunk/lib/Support/SourceMgr.cpp

Jordan Rose jordan_rose at apple.com
Thu Jan 10 18:37:55 PST 2013


Author: jrose
Date: Thu Jan 10 20:37:55 2013
New Revision: 172164

URL: http://llvm.org/viewvc/llvm-project?rev=172164&view=rev
Log:
SMDiagnostic: don't emit ranges if there are /any/ multibyte characters.

Right now, only OS X has a way to determine the column width of a string
(PR14910). Until we have a good way to deal with this, we just won't
print carets, source ranges, or fixits for SMDiagnostic if the source line
has multibyte characters in it.

Modified:
    llvm/trunk/lib/Support/SourceMgr.cpp

Modified: llvm/trunk/lib/Support/SourceMgr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/SourceMgr.cpp?rev=172164&r1=172163&r2=172164&view=diff
==============================================================================
--- llvm/trunk/lib/Support/SourceMgr.cpp (original)
+++ llvm/trunk/lib/Support/SourceMgr.cpp Thu Jan 10 20:37:55 2013
@@ -336,6 +336,10 @@
   S << '\n';
 }
 
+static bool isNonASCII(char c) {
+  return c & 0x80;
+}
+
 void SMDiagnostic::print(const char *ProgName, raw_ostream &S,
                          bool ShowColors) const {
   // Display colors only if OS supports colors.
@@ -392,18 +396,17 @@
   if (LineNo == -1 || ColumnNo == -1)
     return;
 
-  // FIXME: If there are multibyte characters in the source, all our ranges will
-  // be wrong. To do this properly, we'll need a byte-to-column map like Clang's
-  // TextDiagnostic. For now, we'll just handle tabs by expanding them later,
-  // and bail out rather than show incorrect ranges and misaligned fixits for
-  // any other odd characters.
-  SmallString<128> PrintableLine(LineContents);
-  std::replace(PrintableLine.begin(), PrintableLine.end(), '\t', ' ');
-  size_t NumColumns = (size_t)llvm::sys::locale::columnWidth(PrintableLine);
-  if (NumColumns != PrintableLine.size()) {
+  // FIXME: If there are multibyte or multi-column characters in the source, all
+  // our ranges will be wrong. To do this properly, we'll need a byte-to-column
+  // map like Clang's TextDiagnostic. For now, we'll just handle tabs by
+  // expanding them later, and bail out rather than show incorrect ranges and
+  // misaligned fixits for any other odd characters.
+  if (std::find_if(LineContents.begin(), LineContents.end(), isNonASCII) !=
+      LineContents.end()) {
     printSourceLine(S, LineContents);
     return;
   }
+  size_t NumColumns = LineContents.size();
 
   // Build the line with the caret and ranges.
   std::string CaretLine(NumColumns+1, ' ');





More information about the llvm-commits mailing list