summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/fuzzer/FuzzerBuiltins.h
diff options
context:
space:
mode:
authorJonathan Metzman <metzman@chromium.org>2019-01-09 21:46:09 +0000
committerJonathan Metzman <metzman@chromium.org>2019-01-09 21:46:09 +0000
commit55ddb2c790df459d17d8c675e45c0569765d64cf (patch)
tree1688d98b64ffe37b70587e83dd18003b18a918ab /compiler-rt/lib/fuzzer/FuzzerBuiltins.h
parenta86d5c46e1fc308f5f8feadd923ecede8bd3a94b (diff)
downloadbcm5719-llvm-55ddb2c790df459d17d8c675e45c0569765d64cf.tar.gz
bcm5719-llvm-55ddb2c790df459d17d8c675e45c0569765d64cf.zip
[libfuzzer][MSVC] Make calls to builtin functions work with MSVC
Summary: Replace calls to builtin functions with macros or functions that call the Windows-equivalents when targeting windows and call the original builtin functions everywhere else. This change makes more parts of libFuzzer buildable with MSVC. Reviewers: vitalybuka Reviewed By: vitalybuka Subscribers: mgorny, rnk, thakis Differential Revision: https://reviews.llvm.org/D56439 llvm-svn: 350766
Diffstat (limited to 'compiler-rt/lib/fuzzer/FuzzerBuiltins.h')
-rw-r--r--compiler-rt/lib/fuzzer/FuzzerBuiltins.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/compiler-rt/lib/fuzzer/FuzzerBuiltins.h b/compiler-rt/lib/fuzzer/FuzzerBuiltins.h
new file mode 100644
index 00000000000..a80938d9a54
--- /dev/null
+++ b/compiler-rt/lib/fuzzer/FuzzerBuiltins.h
@@ -0,0 +1,36 @@
+//===- FuzzerBuiltins.h - Internal header for builtins ----------*- C++ -* ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+// Wrapper functions and marcos around builtin functions.
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_FUZZER_BUILTINS_H
+#define LLVM_FUZZER_BUILTINS_H
+
+#include "FuzzerDefs.h"
+
+#if !LIBFUZZER_MSVC
+#include <cstdint>
+
+#define GET_CALLER_PC() __builtin_return_address(0)
+
+namespace fuzzer {
+
+inline uint8_t Bswap(uint8_t x) { return x; }
+inline uint16_t Bswap(uint16_t x) { return __builtin_bswap16(x); }
+inline uint32_t Bswap(uint32_t x) { return __builtin_bswap32(x); }
+inline uint64_t Bswap(uint64_t x) { return __builtin_bswap64(x); }
+
+inline uint32_t Clzll(unsigned long long X) { return __builtin_clzll(X); }
+inline uint32_t Clz(unsigned long long X) { return __builtin_clz(X); }
+inline int Popcountll(unsigned long long X) { return __builtin_popcountll(X); }
+
+} // namespace fuzzer
+
+#endif // !LIBFUZZER_MSVC
+#endif // LLVM_FUZZER_BUILTINS_H
OpenPOWER on IntegriCloud