summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/SourceMgr.cpp
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2013-01-11 02:37:55 +0000
committerJordan Rose <jordan_rose@apple.com>2013-01-11 02:37:55 +0000
commitceb1dbb41f6d7eaa3b45793d3307fe092f635167 (patch)
tree0cac73efda7ab44fd53f0ae9a21fe185c5e78d23 /llvm/lib/Support/SourceMgr.cpp
parent78dd388afbd183060b321d001e367dcb50975eb8 (diff)
downloadbcm5719-llvm-ceb1dbb41f6d7eaa3b45793d3307fe092f635167.tar.gz
bcm5719-llvm-ceb1dbb41f6d7eaa3b45793d3307fe092f635167.zip
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. llvm-svn: 172164
Diffstat (limited to 'llvm/lib/Support/SourceMgr.cpp')
-rw-r--r--llvm/lib/Support/SourceMgr.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/llvm/lib/Support/SourceMgr.cpp b/llvm/lib/Support/SourceMgr.cpp
index 58a7713b4d1..fa82265f380 100644
--- a/llvm/lib/Support/SourceMgr.cpp
+++ b/llvm/lib/Support/SourceMgr.cpp
@@ -336,6 +336,10 @@ static void printSourceLine(raw_ostream &S, StringRef LineContents) {
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 @@ void SMDiagnostic::print(const char *ProgName, raw_ostream &S,
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, ' ');
OpenPOWER on IntegriCloud