8cc
8cc copied to clipboard
maybe bug in gen.c
In push_struct function in gen.c, there are three for loops, but it seems that only first for loop is executed, the last two for loops is not executed
int i = 0; for (; i < size; i += 8) { emit("movq %d(#rcx), #r11", i); emit("mov #r11, %d(#rsp)", i); } for (; i < size; i += 4) { emit("movl %d(#rcx), #r11", i); emit("movl #r11d, %d(#rsp)", i); } for (; i < size; i++) { emit("movb %d(#rcx), #r11", i); emit("movb #r11b, %d(#rsp)", i); }
Good spotting, its intending to copy in chunks of 8, then chunks of 4 then finish of the remaining bytes. The logic is wrong, it should be (i + 8) < size, then (i + 4) < size. Maybe it should be rewritten to decrement a value so it is more clear.
*edit: The alignment requirements on structs and the stack may mean this does little harm.
Same issue in emit_copy_struct