// prog.c
#include <stdio.h>
int main(void) {
char c;
printf("%zd", sizeof c);
printf("%zd", sizeof +c);
printf("%zd", sizeof ~c);
printf("%zd", sizeof -c);
}
from my reading of the standard the output should be '1444' and GCC agrees but chibicc outputs '1114'.
$ gcc prog.c && ./a.out
1444
$ ./chibicc prog.c && ./a.out
1114
ISO/IEC 9899:TC3 $6.5.3.3 'Unary arithmetic operators':
- The result of the unary + operator is the value of its (promoted) operand. The integer promotions are performed on the operand, and the result has the promoted type.
- The result of the unary - operator is the negative of its (promoted) operand. The integer promotions are performed on the operand, and the result has the promoted type.
- The result of the ~ operator is the bitwise complement of its (promoted) operand (that is, each bit in the result is set if and only if the corresponding bit in the converted operand is not set). The integer promotions are performed on the operand, and the result has the promoted type. [...]
after a quick look at some disassemblies it looks like chibicc always zero- or sign- extends small integer types into eax anyway, so I couldn't get codegen to misbehave and the issue remains isolated to the typechecker.
from my reading of the standard the output should be '1444' and GCC agrees but chibicc outputs '1114'.
ISO/IEC 9899:TC3 $6.5.3.3 'Unary arithmetic operators':
after a quick look at some disassemblies it looks like chibicc always zero- or sign- extends small integer types into
eaxanyway, so I couldn't get codegen to misbehave and the issue remains isolated to the typechecker.