aboutsummaryrefslogtreecommitdiff
path: root/compiler-rt/include
diff options
context:
space:
mode:
authorMax Moroz <mmoroz@chromium.org>2020-12-30 10:10:23 -0800
committerMax Moroz <mmoroz@chromium.org>2020-12-30 10:25:26 -0800
commit70de7e0d9a95b7fcd7c105b06bd90fdf4e01f563 (patch)
tree9b33f63633ef9872ac198380c5d5c10bff0d969c /compiler-rt/include
parentfe431103b633278da9ece1e03d6b441c1d44d977 (diff)
downloadllvm-70de7e0d9a95b7fcd7c105b06bd90fdf4e01f563.zip
llvm-70de7e0d9a95b7fcd7c105b06bd90fdf4e01f563.tar.gz
llvm-70de7e0d9a95b7fcd7c105b06bd90fdf4e01f563.tar.bz2
[compiler-rt] FuzzedDataProvider: Add PickValueInArray for std::array
This makes `PickValueInArray` work for `std::array<T, s>` (C++11). I've also tested the C++17 `std::array` (with compiler-deduced template parameters) ``` Author: MarcoFalke <falke.marco@gmail.com> ``` Reviewed By: Dor1s Differential Revision: https://reviews.llvm.org/D93412
Diffstat (limited to 'compiler-rt/include')
-rw-r--r--compiler-rt/include/fuzzer/FuzzedDataProvider.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/compiler-rt/include/fuzzer/FuzzedDataProvider.h b/compiler-rt/include/fuzzer/FuzzedDataProvider.h
index 83bcd013..744a9d7 100644
--- a/compiler-rt/include/fuzzer/FuzzedDataProvider.h
+++ b/compiler-rt/include/fuzzer/FuzzedDataProvider.h
@@ -14,6 +14,7 @@
#define LLVM_FUZZER_FUZZED_DATA_PROVIDER_H_
#include <algorithm>
+#include <array>
#include <climits>
#include <cstddef>
#include <cstdint>
@@ -71,6 +72,8 @@ class FuzzedDataProvider {
// Returns a value from the given array.
template <typename T, size_t size> T PickValueInArray(const T (&array)[size]);
+ template <typename T, size_t size>
+ T PickValueInArray(const std::array<T, size> &array);
template <typename T> T PickValueInArray(std::initializer_list<const T> list);
// Writes data to the given destination and returns number of bytes written.
@@ -301,6 +304,12 @@ T FuzzedDataProvider::PickValueInArray(const T (&array)[size]) {
return array[ConsumeIntegralInRange<size_t>(0, size - 1)];
}
+template <typename T, size_t size>
+T FuzzedDataProvider::PickValueInArray(const std::array<T, size> &array) {
+ static_assert(size > 0, "The array must be non empty.");
+ return array[ConsumeIntegralInRange<size_t>(0, size - 1)];
+}
+
template <typename T>
T FuzzedDataProvider::PickValueInArray(std::initializer_list<const T> list) {
// TODO(Dor1s): switch to static_assert once C++14 is allowed.