#17 type inference wrong.

Bug
closed-works-for-me
nobody
5
2006-01-11
2005-12-04
Anonymous
No

In the attached program, the expression
((long long)i << 58ULL) should be typed
(unsigned long long). cil seems to typed
it as (long long), as a result, the
cast operator (signed long long) was omitted
in the C output, and the final result became
a positive number. It should be a positive.

Jianwen Zhu
Electrial and Computer Engineering
University of Toronto
-------------------------------------------------------

int main() {
unsigned i;

for (i = 32; i < 33; i++) {
printf("%f\n",
(double)(signed long
long)((long long)i << 58ULL));
}
}

Discussion

  • Matt Harren
    Matt Harren
    2005-12-04

    Logged In: YES
    user_id=1278428

    According to the C spec, shifts have the type of their left
    operand, and long long is the same as signed long long. So
    ((long long)i << 58ULL) has type long long, and the extra
    cast to signed long long is unneeded.

    I get the same results (-9223372036854775800) for your test
    program with gcc, cl, and cilly. Is there a compiler that
    doesn't agree with these?

     
  • Matt Harren
    Matt Harren
    2005-12-04

    • status: open --> pending-works-for-me
     
  • Logged In: YES
    user_id=1312539

    This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 14 days (the time period specified by
    the administrator of this Tracker).

     
    • status: pending-works-for-me --> closed-works-for-me