fuhsnn / slimcc

C11 compiler with GNU / C23 extensions for x86-64 Linux, able to build Python and PostgreSQL
MIT License
24 stars 3 forks source link

Bit-shift missing integer promotion #38

Closed fuhsnn closed 9 months ago

fuhsnn commented 9 months ago
#include <stdio.h>
int main(void) {
    signed char c = 1;
    printf("%d\n",(int)(signed char)(c << 7)); // expect -128, got 128
    printf("%d\n",sizeof(c << 7)); // expect 4, got 1

    short s = 1;
    printf("%d\n",(int)(short)(s << 15)); // expect -32768, got 32768
    printf("%d\n",sizeof(s << 15)); // expect 4, got 2
}