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

Output of assign-to-bitfield expression #27

Closed fuhsnn closed 10 months ago

fuhsnn commented 10 months ago

Expect post-AND, sign-extended value. clang/gcc warn with -Woverflow but still compiles like this:

#include <stdio.h>
int main (void){
    struct {
        int i : 2;
        _Bool b : 1;
        unsigned j : 2;
    } s;
    int x = s.i = -5;
    int y = s.j = 5;
    printf("%d, %d\n", x, y); // expect -1,1; got -5,5
    x = s.i += -5;
    y = s.j += 5;
    printf("%d, %d\n", x, y); // expect -2,2; got -6,6
}