[compiler-rt] r210335 - [msan] Fix wrong endianness when printing shadow.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Fri Jun 6 07:06:14 PDT 2014


Author: eugenis
Date: Fri Jun  6 09:06:14 2014
New Revision: 210335

URL: http://llvm.org/viewvc/llvm-project?rev=210335&view=rev
Log:
[msan] Fix wrong endianness when printing shadow.

Added:
    compiler-rt/trunk/test/msan/msan_print_shadow3.cc   (with props)
Modified:
    compiler-rt/trunk/lib/msan/msan.cc
    compiler-rt/trunk/lib/msan/msan_report.cc

Modified: compiler-rt/trunk/lib/msan/msan.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan.cc?rev=210335&r1=210334&r2=210335&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan.cc (original)
+++ compiler-rt/trunk/lib/msan/msan.cc Fri Jun  6 09:06:14 2014
@@ -440,7 +440,11 @@ void __msan_dump_shadow(const void *x, u
 
   unsigned char *s = (unsigned char*)MEM_TO_SHADOW(x);
   for (uptr i = 0; i < size; i++) {
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+    Printf("%x%x ", s[i] & 0xf, s[i] >> 4);
+#else
     Printf("%x%x ", s[i] >> 4, s[i] & 0xf);
+#endif
   }
   Printf("\n");
 }

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=210335&r1=210334&r2=210335&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_report.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_report.cc Fri Jun  6 09:06:14 2014
@@ -221,7 +221,11 @@ void DescribeMemoryRange(const void *x,
     } else {
       unsigned char v = *(unsigned char *)s;
       if (v) last_quad_poisoned = true;
-      Printf("%02x", v);
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+      Printf("%x%x", v & 0xf, v >> 4);
+#else
+      Printf("%x%x", v >> 4, v & 0xf);
+#endif
     }
     // Group end.
     if (pos % 4 == 3 && with_origins) {

Added: compiler-rt/trunk/test/msan/msan_print_shadow3.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/msan_print_shadow3.cc?rev=210335&view=auto
==============================================================================
--- compiler-rt/trunk/test/msan/msan_print_shadow3.cc (added)
+++ compiler-rt/trunk/test/msan/msan_print_shadow3.cc Fri Jun  6 09:06:14 2014
@@ -0,0 +1,16 @@
+// RUN: %clangxx_msan -m64 -O0 -g %s -o %t && %run %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out
+
+#include <stdint.h>
+#include <sanitizer/msan_interface.h>
+
+int main(void) {
+  unsigned long long x = 0; // For 8-byte alignment.
+  uint32_t x_s = 0x12345678U;
+  __msan_partial_poison(&x, &x_s, sizeof(x_s));
+  __msan_print_shadow(&x, sizeof(x_s));
+  return 0;
+}
+
+// CHECK: Shadow map of [{{.*}}), 4 bytes:
+// CHECK: 0x{{.*}}: 87654321 ........ ........ ........

Propchange: compiler-rt/trunk/test/msan/msan_print_shadow3.cc
------------------------------------------------------------------------------
    svn:eol-style = LF





More information about the llvm-commits mailing list