overmighty wrote:

Maybe the semantic analysis and docs should have been changed to match GCC's 
better.

GCC's docs say their `__builtin_popcountg` takes a "type-generic unsigned 
integer" but that "No integral argument promotions are performed on the 
argument." Our builtin accepts signed integers too, but the argument goes 
through integer promotion, so the builtin can return an incorrect value if we 
give it a signed integer.

For example, this program will output 32 with Clang on 
`x86_64-unknown-linux-gnu`:

```c
#include <stdio.h>

int main(void) {
    char foo = -1;
    int pop = __builtin_popcountg(foo);
    printf("%d\n", pop);
}
```

GCC refuses to compile it: https://godbolt.org/z/chh4WGT4v.

Should I open a new issue?

https://github.com/llvm/llvm-project/pull/82359
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to