You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@impala.apache.org by "Joe McDonnell (Jira)" <ji...@apache.org> on 2020/05/19 05:35:00 UTC

[jira] [Created] (IMPALA-9762) Fix GCC7 compilation issue: shift-count-overflow in tuple-row-compare.cc

Joe McDonnell created IMPALA-9762:
-------------------------------------

             Summary: Fix GCC7 compilation issue: shift-count-overflow in tuple-row-compare.cc
                 Key: IMPALA-9762
                 URL: https://issues.apache.org/jira/browse/IMPALA-9762
             Project: IMPALA
          Issue Type: Bug
          Components: Backend
    Affects Versions: Impala 4.0
            Reporter: Joe McDonnell


GCC 7 compilation fails on tuple-row-compare.cc with the following:

 
{noformat}
/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
{noformat}
 

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:

 
{code:java}
  return (static_cast<U>(val) <<
      std::max((sizeof(U) - sizeof(T)) * 8, (uint64_t)0)) ^ mask;
{code}
 

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.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)