Uploaded image for project: 'IMPALA'
  1. IMPALA
  2. IMPALA-9762

Fix GCC7 compilation issue: shift-count-overflow in tuple-row-compare.cc

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • Impala 4.0.0
    • Impala 4.0.0
    • Backend
    • None

    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.

      Attachments

        Activity

          People

            joemcdonnell Joe McDonnell
            joemcdonnell Joe McDonnell
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: