diff options
author | Eric Fiselier <eric@efcs.ca> | 2019-12-11 16:36:21 -0500 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2019-12-11 16:36:54 -0500 |
commit | 5c9816b84e94dd380e7b07ac15f619513a7911a8 (patch) | |
tree | 1834c9bb250338583ea2b3c073955ee9d88f58e4 /libcxx/fuzzing | |
parent | 0ca0fba94d48959a8c5d1e074c8242e46b263d59 (diff) | |
download | bcm5719-llvm-5c9816b84e94dd380e7b07ac15f619513a7911a8.tar.gz bcm5719-llvm-5c9816b84e94dd380e7b07ac15f619513a7911a8.zip |
[libc++] Fix fuzzing tests with older GCC compilers.
GCC 5 doesn't support `if constexpr`, so we need to do old-style tag
dispatching.
Diffstat (limited to 'libcxx/fuzzing')
-rw-r--r-- | libcxx/fuzzing/fuzzing.cpp | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/libcxx/fuzzing/fuzzing.cpp b/libcxx/fuzzing/fuzzing.cpp index 9f3601fbf0b..d036f0cbb8b 100644 --- a/libcxx/fuzzing/fuzzing.cpp +++ b/libcxx/fuzzing/fuzzing.cpp @@ -652,6 +652,8 @@ enum InitKind { VectorResultType }; + + template <class Dist> struct ParamTypeHelper { using ParamT = typename Dist::param_type; @@ -659,16 +661,24 @@ struct ParamTypeHelper { static_assert(std::is_same<ResultT, typename ParamT::distribution_type::result_type>::value, ""); static ParamT Create(const uint8_t* data, size_t size, bool &OK) { - if constexpr (std::is_constructible<ParamT, ResultT*, ResultT*, ResultT*>::value) - return CreateVectorResult(data, size, OK); - else if constexpr (std::is_constructible<ParamT, double*, double*>::value) - return CreateVectorDouble(data, size, OK); - else - return CreateDefault(data, size, OK); + constexpr bool select_vector_result = std::is_constructible<ParamT, ResultT*, ResultT*, ResultT*>::value; + constexpr bool select_vector_double = std::is_constructible<ParamT, double*, double*>::value; + constexpr int selector = select_vector_result ? 0 : (select_vector_double ? 1 : 2); + return DispatchAndCreate(std::integral_constant<int, selector>{}, data, size, OK); + } + static ParamT DispatchAndCreate(std::integral_constant<int, 0>, const uint8_t *data, size_t size, bool &OK) { + return CreateVectorResult(data, size, OK); + } + static ParamT DispatchAndCreate(std::integral_constant<int, 1>, const uint8_t *data, size_t size, bool &OK) { + return CreateVectorDouble(data, size, OK); + } + static ParamT DispatchAndCreate(std::integral_constant<int, 2>, const uint8_t *data, size_t size, bool &OK) { + return CreateDefault(data, size, OK); + } -static ParamT +static ParamT CreateVectorResult(const uint8_t *data, size_t size, bool &OK) { auto Input = GetValues<ResultT>(data, size); OK = false; |