[llvm-bugs] [Bug 24805] Inconsistent behavior in FP_TO_UINT compared to gcc-4.9
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Sep 17 06:04:45 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=24805
John Brawn <john.brawn at arm.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |INVALID
CC| |john.brawn at arm.com
--- Comment #1 from John Brawn <john.brawn at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200917/b7d35b09/attachment-0001.html>
More information about the llvm-bugs
mailing list