[PATCH] D66433: LibFuzzer support for 32bit MSVC

Max Shavrick via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 19 11:43:07 PDT 2019


mxms created this revision.
mxms added reviewers: rnk, zturner, vitalybuka.
mxms created this object with visibility "All Users".
Herald added projects: LLVM, Sanitizers.
Herald added subscribers: Sanitizers, llvm-commits.

This fixes the two build errors when trying to compile LibFuzzer for 32bit with MSVC.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D66433

Files:
  lib/fuzzer/FuzzerBuiltinsMsvc.h


Index: lib/fuzzer/FuzzerBuiltinsMsvc.h
===================================================================
--- lib/fuzzer/FuzzerBuiltinsMsvc.h
+++ lib/fuzzer/FuzzerBuiltinsMsvc.h
@@ -15,9 +15,6 @@
 #include "FuzzerDefs.h"

 #if LIBFUZZER_MSVC
-#if !defined(_M_ARM) && !defined(_M_X64)
-#error "_BitScanReverse64 unavailable on this platform so MSVC is unsupported."
-#endif
 #include <intrin.h>
 #include <cstdint>
 #include <cstdlib>
@@ -40,8 +37,19 @@
 // outside of Windows.
 inline uint32_t Clzll(uint64_t X) {
   unsigned long LeadZeroIdx = 0;
+
+#if !defined(_M_ARM) && !defined(_M_X64)
+  // Scan the high 32 bits.
+  if (_BitScanReverse(&LeadZeroIdx, static_cast<unsigned long>(X >> 32)))
+    return static_cast<int>(63 - (LeadZeroIdx + 32)); // Create a bit offset from the MSB.
+  // Scan the low 32 bits.
+  if (_BitScanReverse(&LeadZeroIdx, static_cast<unsigned long>(X)))
+    return static_cast<int>(63 - LeadZeroIdx);
+
+#else
   if (_BitScanReverse64(&LeadZeroIdx, X)) return 63 - LeadZeroIdx;
-  return 64;
+#endif
+  return 64;
 }

 inline uint32_t Clz(uint32_t X) {
@@ -50,7 +58,13 @@
   return 32;
 }

-inline int Popcountll(unsigned long long X) { return __popcnt64(X); }
+inline int Popcountll(unsigned long long X) {
+#if !defined(_M_ARM) && !defined(_M_X64)
+  return __popcnt(X);
+#else
+  return __popcnt64(X);
+#endif
+}

 }  // namespace fuzzer



-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66433.215685.patch
Type: text/x-patch
Size: 1375 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190819/3f7587e3/attachment.bin>


More information about the llvm-commits mailing list