Highlight caret in bold green, to match Clang diagnostics.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 12 Feb 2013 22:12:10 +0000 (22:12 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 12 Feb 2013 22:12:10 +0000 (22:12 +0000)
llvm-svn: 175013

compiler-rt/lib/ubsan/ubsan_diag.cc

index 57c98e6..95fad74 100644 (file)
@@ -156,7 +156,7 @@ static Range *upperBound(MemoryLocation Loc, Range *Ranges,
 }
 
 /// Render a snippet of the address space near a location.
-static void renderMemorySnippet(MemoryLocation Loc,
+static void renderMemorySnippet(bool UseAnsiColor, MemoryLocation Loc,
                                 Range *Ranges, unsigned NumRanges,
                                 const Diag::Arg *Args) {
   const unsigned BytesToShow = 32;
@@ -183,6 +183,8 @@ static void renderMemorySnippet(MemoryLocation Loc,
   RawWrite("\n");
 
   // Emit highlights.
+  if (UseAnsiColor)
+    RawWrite("\033[1;32m");
   Range *InRange = upperBound(Min, Ranges, NumRanges);
   for (uptr P = Min; P != Max; ++P) {
     char Pad = ' ', Byte = ' ';
@@ -197,6 +199,8 @@ static void renderMemorySnippet(MemoryLocation Loc,
     char Buffer[] = { Pad, Pad, P == Loc ? '^' : Byte, Byte, 0 };
     RawWrite((P % 8 == 0) ? Buffer : &Buffer[1]);
   }
+  if (UseAnsiColor)
+    RawWrite("\033[0m");
   RawWrite("\n");
 
   // Go over the line again, and print names for the ranges.
@@ -267,5 +271,6 @@ Diag::~Diag() {
   RawWrite("\n");
 
   if (Loc.isMemoryLocation())
-    renderMemorySnippet(Loc.getMemoryLocation(), Ranges, NumRanges, Args);
+    renderMemorySnippet(UseAnsiColor, Loc.getMemoryLocation(), Ranges,
+                        NumRanges, Args);
 }