[PATCH] [ASan] Fix MSVC -W3 warnings when building the Windows RTL

Timur Iskhodzhanov timurrrr at google.com
Wed May 29 05:46:06 PDT 2013


Hi kcc,

http://llvm-reviews.chandlerc.com/D885

Files:
  asan/asan_fake_stack.h
  asan/asan_interceptors.cc
  asan/asan_poisoning.h
  asan/asan_report.cc
  sanitizer_common/sanitizer_allocator.h
  sanitizer_common/sanitizer_common_libcdep.cc
  sanitizer_common/sanitizer_flags.cc
  sanitizer_common/sanitizer_printf.cc

Index: asan/asan_fake_stack.h
===================================================================
--- asan/asan_fake_stack.h
+++ asan/asan_fake_stack.h
@@ -23,7 +23,7 @@
   uptr descr;  // Modified by the instrumented code.
   uptr pc;     // Modified by the instrumented code.
   u64 real_stack     : 48;
-  u64 size_minus_one : 16;
+  uptr size_minus_one : 16;
   // End of the first 32 bytes.
   // The rest should not be used when the frame is active.
   FakeFrame *next;
@@ -80,7 +80,7 @@
   static void OnFree(uptr ptr, uptr size, uptr real_stack);
   // Return the bottom of the maped region.
   uptr AddrIsInFakeStack(uptr addr);
-  bool StackSize() { return stack_size_; }
+  uptr StackSize() const { return stack_size_; }
 
  private:
   static const uptr kMinStackFrameSizeLog = 9;  // Min frame is 512B.
Index: asan/asan_interceptors.cc
===================================================================
--- asan/asan_interceptors.cc
+++ asan/asan_interceptors.cc
@@ -673,7 +673,7 @@
   u32 current_tid = GetCurrentTidOrInvalid();
   AsanThread *t = AsanThread::Create(start_routine, arg);
   CreateThreadContextArgs args = { t, &stack };
-  int detached = 0;  // FIXME: how can we determine it on Windows?
+  bool detached = 0;  // FIXME: how can we determine it on Windows?
   asanThreadRegistry().CreateThread(*(uptr*)t, detached, current_tid, &args);
   return REAL(CreateThread)(security, stack_size,
                             asan_thread_start, t, flags, tid);
Index: asan/asan_poisoning.h
===================================================================
--- asan/asan_poisoning.h
+++ asan/asan_poisoning.h
@@ -50,7 +50,7 @@
     } else if (i >= size) {
       *shadow = (SHADOW_GRANULARITY == 128) ? 0xff : value;  // unaddressable
     } else {
-      *shadow = size - i;  // first size-i bytes are addressable
+      *shadow = static_cast<u8>(size - i);  // first size-i bytes are addressable
     }
   }
 }
Index: asan/asan_report.cc
===================================================================
--- asan/asan_report.cc
+++ asan/asan_report.cc
@@ -125,7 +125,7 @@
          "application bytes):\n", (int)SHADOW_GRANULARITY);
   PrintShadowByte("  Addressable:           ", 0);
   Printf("  Partially addressable: ");
-  for (uptr i = 1; i < SHADOW_GRANULARITY; i++)
+  for (u8 i = 1; i < SHADOW_GRANULARITY; i++)
     PrintShadowByte("", i, " ");
   Printf("\n");
   PrintShadowByte("  Heap left redzone:     ", kAsanHeapLeftRedzoneMagic);
@@ -267,7 +267,7 @@
 bool DescribeAddressIfStack(uptr addr, uptr access_size) {
   AsanThread *t = FindThreadByStackAddress(addr);
   if (!t) return false;
-  const sptr kBufSize = 4095;
+  const s64 kBufSize = 4095;
   char buf[kBufSize];
   uptr offset = 0;
   uptr frame_pc = 0;
@@ -306,13 +306,13 @@
   PrintStack(&alloca_stack);
   // Report the number of stack objects.
   char *p;
-  uptr n_objects = internal_simple_strtoll(frame_descr, &p, 10);
+  s64 n_objects = internal_simple_strtoll(frame_descr, &p, 10);
   CHECK_GT(n_objects, 0);
   Printf("  This frame has %zu object(s):\n", n_objects);
   // Report all objects in this frame.
-  for (uptr i = 0; i < n_objects; i++) {
-    uptr beg, size;
-    sptr len;
+  for (s64 i = 0; i < n_objects; i++) {
+    s64 beg, size;
+    s64 len;
     beg  = internal_simple_strtoll(p, &p, 10);
     size = internal_simple_strtoll(p, &p, 10);
     len  = internal_simple_strtoll(p, &p, 10);
@@ -323,7 +323,7 @@
     }
     p++;
     buf[0] = 0;
-    internal_strncat(buf, p, Min(kBufSize, len));
+    internal_strncat(buf, p, static_cast<uptr>(Min(kBufSize, len)));
     p += len;
     Printf("    [%zu, %zu) '%s'\n", beg, beg + size, buf);
   }
Index: sanitizer_common/sanitizer_allocator.h
===================================================================
--- sanitizer_common/sanitizer_allocator.h
+++ sanitizer_common/sanitizer_allocator.h
@@ -779,7 +779,7 @@
     MapUnmapCallback().OnMap(res, kRegionSize);
     stat->Add(AllocatorStatMmapped, kRegionSize);
     CHECK_EQ(0U, (res & (kRegionSize - 1)));
-    possible_regions.set(ComputeRegionId(res), class_id);
+    possible_regions.set(ComputeRegionId(res), static_cast<u8>(class_id));
     return res;
   }
 
Index: sanitizer_common/sanitizer_common_libcdep.cc
===================================================================
--- sanitizer_common/sanitizer_common_libcdep.cc
+++ sanitizer_common/sanitizer_common_libcdep.cc
@@ -17,7 +17,7 @@
 
 bool PrintsToTty() {
   MaybeOpenReportFile();
-  return internal_isatty(report_fd);
+  return internal_isatty(report_fd) != 0;
 }
 
 }  // namespace __sanitizer
Index: sanitizer_common/sanitizer_flags.cc
===================================================================
--- sanitizer_common/sanitizer_flags.cc
+++ sanitizer_common/sanitizer_flags.cc
@@ -97,7 +97,7 @@
   int value_length;
   if (!GetFlagValue(env, name, &value, &value_length))
     return;
-  *flag = internal_atoll(value);
+  *flag = static_cast<int>(internal_atoll(value));
 }
 
 static LowLevelAllocator allocator_for_flags;
Index: sanitizer_common/sanitizer_printf.cc
===================================================================
--- sanitizer_common/sanitizer_printf.cc
+++ sanitizer_common/sanitizer_printf.cc
@@ -59,7 +59,7 @@
   }
   int result = 0;
   while (pos-- > 0) {
-    uptr digit = num_buffer[pos];
+    char digit = static_cast<char>(num_buffer[pos]);
     result += AppendChar(buff, buff_end, (digit < 10) ? '0' + digit
                                                       : 'a' + digit - 10);
   }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D885.1.patch
Type: text/x-patch
Size: 5533 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130529/8ed33591/attachment.bin>


More information about the llvm-commits mailing list