[PATCH] D44559: [Sema] Wrong width of result of mul operation

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 16 11:57:38 PDT 2018

aaron.ballman added a comment.

In https://reviews.llvm.org/D44559#1040398, @craig.topper wrote:

> gcc also warns for this
> short foo(char a) {
>   return a * a;
> }
> Despite the fact that the char would be promoted to int, the upper bits are just sign bits and the multiply result still fits in a short.

But it *should* warn if the underlying char type is unsigned, because 255 * 255 = 65025 which is too large to fit into a signed short.

  rC Clang


More information about the cfe-commits mailing list