#114 Incorrect cast inserted for operands of && and ||

Bug
closed-fixed
nobody
5
2011-09-22
2009-08-13
Anonymous
No

This can only happen when useLogicalOperators is true, but CIL mistakenly casts the operands of && and || to intType. In fact, the operands are only required to have scalar type. This can lead to incorrect behavior if an operand is larger than an int and gets truncated to 0 by this cast. I believe this can be fixed simply by removing these incorrect casts. My only concern is whether enumerations should still be cast to intType or not, but I suspect it is unnecessary.

As an example, this code behaves incorrectly when run with useLogicalOperators set to true:
#include <stdio.h>
int main() {
long long x = 0x100000000LL;
if (x && x) printf("x\n");
return 0;
}

Elnatan Reisner

Discussion

  • Gabriel Kerneis

    Gabriel Kerneis - 2011-09-22
    • status: open --> closed-fixed
     
  • Gabriel Kerneis

    Gabriel Kerneis - 2011-09-22

    Your patch to fix this issue has been merged in trunk a while ago. Thanks.

     

Log in to post a comment.