jserv / MazuCC

A minimalist C compiler with x86_64 code generation
BSD 2-Clause "Simplified" License
516 stars 65 forks source link

Fix wrong shifts on integer expressions #22

Closed Theldus closed 4 years ago

Theldus commented 4 years ago

MazuCC produces wrong shifts (i.e: inverted) on integer expressions. Steps to reproduce:

$ echo "int foo = 16<<2; int bar = 16>>2;" > test.c
$ ./mzcc test.c
        .data                # emit_data_section:724
.global foo                  # emit_global_var -> emit_data:694
foo:                         # emit_global_var -> emit_data:695                 
        .long 4              # emit_global_var -> emit_data -> emit_data_int:681
.global bar                  # emit_global_var -> emit_data:694                 
bar:                         # emit_global_var -> emit_data:695                 
        .long 64             # emit_global_var -> emit_data -> emit_data_int:681

FIx this by inverting the shifts order (left -> right / right -> left) on parser.

jserv commented 4 years ago

Thank @Theldus for spotting this!