diff --git a/apps/hannk/util/buffer_util.h b/apps/hannk/util/buffer_util.h index f9a67a24bacf..d9559b9ab7e8 100644 --- a/apps/hannk/util/buffer_util.h +++ b/apps/hannk/util/buffer_util.h @@ -3,6 +3,7 @@ #include #include +#include #include "HalideBuffer.h" #include "HalideRuntime.h" @@ -191,11 +192,13 @@ struct FillWithRandom { private: inline static void fill_with_random_impl(HalideBuffer &b, std::mt19937 &rng) { - std::uniform_int_distribution dis(std::numeric_limits::min(), - std::numeric_limits::max()); - b.for_each_value([&rng, &dis](T &value) { - value = dis(rng); - }); + // std::uniform_int_distribution is undefined behaviour when T is not + // one of [short, int, long, long long], or their respective unsigned variants. + // (https://en.cppreference.com/w/cpp/numeric/random/uniform_int_distribution) + typedef typename std::conditional= sizeof(int16_t), T, std::int16_t>::type rand_type; + std::uniform_int_distribution dis(std::numeric_limits::min(), + std::numeric_limits::max()); + b.for_each_value([&rng, &dis](T &value) { value = dis(rng); }); } };