This is an automated email from the ASF dual-hosted git repository. joemcdonnell pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/impala.git
The following commit(s) were added to refs/heads/master by this push: new f474b03 IMPALA-9762: Fix GCC7 shift-count-overflow in tuple-row-compare.cc f474b03 is described below commit f474b03dce35956d0762159eed16516b793903eb Author: Joe McDonnell <joemcdonn...@cloudera.com> AuthorDate: Tue May 19 18:36:48 2020 -0700 IMPALA-9762: Fix GCC7 shift-count-overflow in tuple-row-compare.cc This fixes a GCC 7 compilation error for this code in TupleRowZOrderComparator's GetSharedIntRepresentation() and GetSharedFloatRepresentation(): return (static_cast<U>(val) << std::max((sizeof(U) - sizeof(T)) * 8, (uint64_t)0)) ^ mask; In this case, the std::max is running with uint64_t arguments. For template instatiations with sizeof(T) > sizeof(U), this results in integer overflow and a very large positive integer causing the shift-count-overflow. These instantiations are not used by Impala, but the compiler still needs to generate them. This changes the logic to use signed integers for the std::max, avoiding the shift-count-overflow. Testing: - Build on GCC 4.9.2 and GCC 7 - Core tests Change-Id: I518e8bed1bb8d49d9cb76a33b07b665e15dfef87 Reviewed-on: http://gerrit.cloudera.org:8080/15962 Reviewed-by: Impala Public Jenkins <impala-public-jenk...@cloudera.com> Tested-by: Impala Public Jenkins <impala-public-jenk...@cloudera.com> --- be/src/util/tuple-row-compare.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/be/src/util/tuple-row-compare.cc b/be/src/util/tuple-row-compare.cc index d960bbe..099fa46 100644 --- a/be/src/util/tuple-row-compare.cc +++ b/be/src/util/tuple-row-compare.cc @@ -439,8 +439,9 @@ U TupleRowZOrderComparator::GetSharedRepresentation(void* val, ColumnType type) template <typename U, typename T> U inline TupleRowZOrderComparator::GetSharedIntRepresentation(const T val, U mask) const { - return (static_cast<U>(val) << - std::max((sizeof(U) - sizeof(T)) * 8, (uint64_t)0)) ^ mask; + uint64_t shift_size = static_cast<uint64_t>( + std::max(static_cast<int64_t>((sizeof(U) - sizeof(T)) * 8), (int64_t) 0)); + return (static_cast<U>(val) << shift_size) ^ mask; } template <typename U, typename T> @@ -449,13 +450,14 @@ U inline TupleRowZOrderComparator::GetSharedFloatRepresentation(void* val, U mas T floating_value = *reinterpret_cast<const T*>(val); memcpy(&tmp, &floating_value, sizeof(T)); if (UNLIKELY(std::isnan(floating_value))) return 0; + uint64_t shift_size = static_cast<uint64_t>( + std::max(static_cast<int64_t>((sizeof(U) - sizeof(T)) * 8), (int64_t) 0)); if (floating_value < 0.0) { // Flipping all bits for negative values. - return static_cast<U>(~tmp) << std::max((sizeof(U) - sizeof(T)) * 8, (uint64_t)0); + return static_cast<U>(~tmp) << shift_size; } else { // Flipping only first bit. - return (static_cast<U>(tmp) << std::max((sizeof(U) - sizeof(T)) * 8, (uint64_t)0)) ^ - mask; + return (static_cast<U>(tmp) << shift_size) ^ mask; } }