https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67483

            Bug ID: 67483
           Summary: combine.c sanitizer detects undefined negative left
                    shift
           Product: gcc
           Version: 5.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zeccav at gmail dot com
  Target Milestone: ---

//g++ -ftracer -O2
//g++ 5.2.0 undefined left shift
//../../gcc-5.2.0/gcc/combine.c:7696:40: runtime error: shift exponent -1 is
negative
//offending line "& ((((unsigned HOST_WIDE_INT) 1 << count)) - 1)) == 0"
//in extract_left_shift
// count == -1 thus negative shift exponent
// Target: x86_64-unknown-linux-gnu
struct double_int
{
 double_int sext (unsigned prec) const;
 static double_int mask (unsigned prec);
 unsigned low;/*unsigned long int low provokes same bug at combine.c:12078*/
};

double_int
double_int::mask (unsigned prec)
{
  double_int mask;
  if (prec <= 64) mask.low = prec ? ((unsigned long) 2 << (prec - 1)) - 1 : 0;
  return mask;
}

double_int
double_int::sext (unsigned prec) const
{
  const double_int &cst = *this;
  double_int mask = double_int::mask (prec);
  double_int r; 
  unsigned long snum;
  if (prec <= 64) snum = cst.low;
  if (((snum >> (prec - 1)) & 1) == 1)
    {
     r.low = cst.low ;
    }
  else
    {
     r.low = mask.low;
    }
  return r;
}

Reply via email to