[llvm-commits] [compiler-rt] r171106 - /compiler-rt/trunk/lib/msan/msan_report.cc

Evgeniy Stepanov eugeni.stepanov at gmail.com
Wed Dec 26 02:16:46 PST 2012


Author: eugenis
Date: Wed Dec 26 04:16:45 2012
New Revision: 171106

URL: http://llvm.org/viewvc/llvm-project?rev=171106&view=rev
Log:
[msan] MSan, New Year Tree style.

Modified:
    compiler-rt/trunk/lib/msan/msan_report.cc

Modified: compiler-rt/trunk/lib/msan/msan_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_report.cc?rev=171106&r1=171105&r2=171106&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_report.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_report.cc Wed Dec 26 04:16:45 2012
@@ -15,6 +15,7 @@
 #include "msan.h"
 #include "sanitizer_common/sanitizer_common.h"
 #include "sanitizer_common/sanitizer_mutex.h"
+#include "sanitizer_common/sanitizer_report_decorator.h"
 #include "sanitizer_common/sanitizer_stackdepot.h"
 
 using namespace __sanitizer;
@@ -23,7 +24,27 @@
 
 namespace __msan {
 
+static bool PrintsToTtyCached() {
+  static int cached = 0;
+  static bool prints_to_tty;
+  if (!cached) {  // Ok wrt threads since we are printing only from one thread.
+    prints_to_tty = PrintsToTty();
+    cached = 1;
+  }
+  return prints_to_tty;
+}
+
+class Decorator: private __sanitizer::AnsiColorDecorator {
+ public:
+  Decorator() : __sanitizer::AnsiColorDecorator(PrintsToTtyCached()) { }
+  const char *Warning()    { return Red(); }
+  const char *Origin()     { return Magenta(); }
+  const char *Name()   { return Green(); }
+  const char *End()    { return Default(); }
+};
+
 static void DescribeOrigin(u32 origin) {
+  Decorator d;
   if (flags()->verbosity)
     Printf("  raw origin id: %d\n", origin);
   if (const char *so = __msan_get_origin_descr_if_stack(origin)) {
@@ -31,13 +52,17 @@
     char* sep = internal_strchr(s, '@');
     CHECK(sep);
     *sep = '\0';
-    Printf("  Uninitialised value was created by an allocation of '%s'"
-           " in the stack frame of function '%s'\n", s, sep + 1);
+    Printf("%s", d.Origin());
+    Printf("  %sUninitialised value was created by an allocation of '%s%s%s'"
+           " in the stack frame of function '%s%s%s'%s\n",
+           d.Origin(), d.Name(), s, d.Origin(), d.Name(), sep + 1,
+           d.Origin(), d.End());
     InternalFree(s);
   } else {
     uptr size = 0;
     const uptr *trace = StackDepotGet(origin, &size);
-    Printf("  Uninitialised value was created by a heap allocation\n");
+    Printf("  %sUninitialised value was created by a heap allocation%s\n",
+           d.Origin(), d.End());
     StackTrace::PrintStack(trace, size, true, "", 0);
   }
 }
@@ -47,7 +72,10 @@
 
   GenericScopedLock<StaticSpinMutex> lock(&report_mu);
 
+  Decorator d;
+  Printf("%s", d.Warning());
   Report(" WARNING: Use of uninitialized value\n");
+  Printf("%s", d.End());
   StackTrace::PrintStack(stack->trace, stack->size, true, "", 0);
   if (origin) {
     DescribeOrigin(origin);





More information about the llvm-commits mailing list