Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
Impala 4.0.0
-
None
-
ghx-label-4
Description
GCC 7 compilation fails on tuple-row-compare.cc with the following:
/home/joe/view2/Impala/be/src/util/tuple-row-compare.cc: In instantiation of \u2018U impala::TupleRowZOrderComparator::GetSharedFloatRepresentation(void*, U) const [with U = unsigned int; T = double]\u2019: /home/joe/view2/Impala/be/src/util/tuple-row-compare.cc:405:53: required from \u2018U impala::TupleRowZOrderComparator::GetSharedRepresentation(void*, impala::ColumnType) const [with U = unsigned int]\u2019 /home/joe/view2/Impala/be/src/util/tuple-row-compare.cc:357:41: required from \u2018int impala::TupleRowZOrderComparator::CompareBasedOnSize(const impala::TupleRow*, const impala::TupleRow*) const [with U = unsigned int]\u2019 /home/joe/view2/Impala/be/src/util/tuple-row-compare.cc:343:49: required from here /home/joe/view2/Impala/be/src/util/tuple-row-compare.cc:454:33: error: left shift count >= width of type [-Werror=shift-count-overflow] return static_cast<U>(~tmp) << std::max((sizeof(U) - sizeof(T)) * 8, (uint64_t)0); ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/joe/view2/Impala/be/src/util/tuple-row-compare.cc:457:33: error: left shift count >= width of type [-Werror=shift-count-overflow] return (static_cast<U>(tmp) << std::max((sizeof(U) - sizeof(T)) * 8, (uint64_t)0)) ^ ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1plus: all warnings being treated as errors
What is happening is that GCC is creating some template instantiations of TupleRowZOrderComparator::GetSharedRepresentation() and TupleRowZOrderComparator::CompareBasedOnSize(). The code at issue is doing this calculation:
return (static_cast<U>(val) <<
std::max((sizeof(U) - sizeof(T)) * 8, (uint64_t)0)) ^ mask;
However, for these template instantiations, sizeof(T) > sizeof(U). That condition is impossible and never executed in Impala, but the instantiation exists. The compiler is intepreting the sizeof(U) - sizeof(T) not as a negative integer, but as a very very large positive integer (maybe due to the uint64_t 0). It wins the max calculation and triggers the shift-count-overflow.
The fix is to do the max calculation with signed integers and then cast it to unsigned for the shift.