]> granicus.if.org Git - clang/commitdiff
restructure code a bit: there are two potential issues
authorChris Lattner <sabre@nondot.org>
Fri, 12 Feb 2010 18:52:52 +0000 (18:52 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 12 Feb 2010 18:52:52 +0000 (18:52 +0000)
worth asserting about in this code: 1) if the source range
is bogus (begin loc after end loc), and 2) if the client
is trying to highlight a range that is purely whitespace.

It is possible to just silently ignore #2, but it seems like
it is always a bug, so lets keep asserting on this condition,
but with a better assert message.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95998 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/TextDiagnosticPrinter.cpp

index 83b4542caa255b3e05fe39e21b88b6e3c36cf5f4..9ec5ffe1c353dc2a4c921d993796d858b771e53d 100644 (file)
@@ -104,11 +104,6 @@ void TextDiagnosticPrinter::HighlightRange(const SourceRange &R,
     if (StartColNo) --StartColNo;  // Zero base the col #.
   }
 
-  // Pick the first non-whitespace column.
-  while (StartColNo < SourceLine.size() &&
-         (SourceLine[StartColNo] == ' ' || SourceLine[StartColNo] == '\t'))
-    ++StartColNo;
-
   // Compute the column number of the end.
   unsigned EndColNo = CaretLine.size();
   if (EndLineNo == LineNo) {
@@ -123,16 +118,25 @@ void TextDiagnosticPrinter::HighlightRange(const SourceRange &R,
     }
   }
 
+  assert(StartColNo <= EndColNo && "Invalid range!");
+  
+  // Pick the first non-whitespace column.
+  while (StartColNo < SourceLine.size() &&
+         (SourceLine[StartColNo] == ' ' || SourceLine[StartColNo] == '\t'))
+    ++StartColNo;
+  
   // Pick the last non-whitespace column.
-  if (EndColNo <= SourceLine.size())
-    while (EndColNo-1 &&
-           (SourceLine[EndColNo-1] == ' ' || SourceLine[EndColNo-1] == '\t'))
-      --EndColNo;
-  else
+  if (EndColNo > SourceLine.size())
     EndColNo = SourceLine.size();
+  while (EndColNo-1 &&
+         (SourceLine[EndColNo-1] == ' ' || SourceLine[EndColNo-1] == '\t'))
+    --EndColNo;
+  
+  // If the start/end passed each other, then we are trying to highlight a range
+  // that just exists in whitespace, which must be some sort of other bug.
+  assert(StartColNo <= EndColNo && "Trying to highlight whitespace??");
 
   // Fill the range with ~'s.
-  assert(StartColNo <= EndColNo && "Invalid range!");
   for (unsigned i = StartColNo; i < EndColNo; ++i)
     CaretLine[i] = '~';
 }