[llvm-commits] [compiler-rt] r168422 - /compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc

Alexey Samsonov samsonov at google.com
Wed Nov 21 03:12:57 PST 2012


Author: samsonov
Date: Wed Nov 21 05:12:57 2012
New Revision: 168422

URL: http://llvm.org/viewvc/llvm-project?rev=168422&view=rev
Log:
[Sanitizer] replace while with internal_memset to make sure compiler won't replace it with library memset

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc?rev=168422&r1=168421&r2=168422&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc Wed Nov 21 05:12:57 2012
@@ -45,7 +45,12 @@
     num_buffer[pos++] = num % base;
     num /= base;
   } while (num > 0);
-  while (pos < minimal_num_length) num_buffer[pos++] = 0;
+  if (pos < minimal_num_length) {
+    // Make sure compiler doesn't insert call to memset here.
+    internal_memset(&num_buffer[pos], 0,
+                    sizeof(num_buffer[0]) * (minimal_num_length - pos));
+    pos = minimal_num_length;
+  }
   int result = 0;
   while (pos-- > 0) {
     uptr digit = num_buffer[pos];





More information about the llvm-commits mailing list