-
- Downloads
tccgen: fix casts using code from upstream
We detected issues: tcc-mob built with us was failing to compile code like: unsigned long x = 0xcafecafe; It was applying sign extension, producing a `x == 0xffffffffcafecafe`. Instead, when built with GCC tcc-mob produced the proper `x == 0xcafecafe`. This is because our casts are faulty in RISC-V because it always sign-extends and we need to clear those high bits after the sign-extension. Proper compilation should produce this after the value is loaded: slli reg, reg, 0x20 // shift left 32 times srli reg, reg, 0x20 // and back Meaning the highest 32 bits are cleared. Our casts didn't detect the need for this, and many appearances of integer constants in tcc-mob were miscompiled, producing future errors in the chain: `load`, code generation, elf... This commit backports the `gen_cast` function from tcc-mob and manipulates the code around it to make it fit in our internals. It's not superclean, but it should work. * arm64-gen.c (gen_cvt_csti): New function for char to int conversion. * i386-gen.c (gen_cvt_csti): Likewise. * x86_64-gen.c (gen_cvt_csti): Likewise. (gen_cvt_sxtw): New function for word sign-extension. * tcc.h: Add them to headers. * tccgen.c (gen_cast): Update from upstream. (btype_size): Add function.
Loading