[compiler-rt] r369704 - LibFuzzer support for 32bit MSVC

Matthew G McGovern via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 22 13:44:35 PDT 2019


Author: mcgov
Date: Thu Aug 22 13:44:34 2019
New Revision: 369704

URL: http://llvm.org/viewvc/llvm-project?rev=369704&view=rev
Log:
LibFuzzer support for 32bit MSVC

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

    - authored by Max Shavrick (mxms at microsoft)

Modified:
    compiler-rt/trunk/lib/fuzzer/FuzzerBuiltinsMsvc.h

Modified: compiler-rt/trunk/lib/fuzzer/FuzzerBuiltinsMsvc.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerBuiltinsMsvc.h?rev=369704&r1=369703&r2=369704&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerBuiltinsMsvc.h (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerBuiltinsMsvc.h Thu Aug 22 13:44:34 2019
@@ -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,7 +37,18 @@ inline uint64_t Bswap(uint64_t x) { retu
 // 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;
+#endif
   return 64;
 }
 
@@ -50,7 +58,13 @@ inline uint32_t Clz(uint32_t X) {
   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) + __popcnt(X >> 32);
+#else
+  return __popcnt64(X);
+#endif
+}
 
 }  // namespace fuzzer
 




More information about the llvm-commits mailing list