https://bugs.llvm.org/show_bug.cgi?id=24805

John Brawn <john.br...@arm.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID
                 CC|                            |john.br...@arm.com

--- Comment #1 from John Brawn <john.br...@arm.com> ---
Adjusting the test case slightly to expand things out:

  int main() {
    a = a * b;
    printf("%d", a);
    return 0;
  }

In 'a * b' as one operand is double the other is converted to double so the
result is a double. That then needs to be converted to unsigned char for the
assignment, which means we actually have:

  int main() {
    a = (unsigned char)((double)a * b);
    printf("%d", a);
    return 0;
  }

According to section 6.3.1.4 of C99: 'If the value of the integral part cannot
be represented by the integer type, the behavior is undefined.' so here we have
undefined behaviour as 255*18=4590 which cannot be represented in unsigned
char.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to