mirror of
git://repo.or.cz/tinycc.git
synced 2026-06-17 15:44:18 +08:00
Fix pointer difference issue in aarch64/riscv64
Some checks failed
build and test / test-x86_64-linux (push) Has been cancelled
build and test / test-x86_64-osx (push) Has been cancelled
build and test / test-aarch64-osx (push) Has been cancelled
build and test / test-x86_64-win32 (push) Has been cancelled
build and test / test-i386-win32 (push) Has been cancelled
build and test / test-armv7-linux (push) Has been cancelled
build and test / test-aarch64-linux (push) Has been cancelled
build and test / test-riscv64-linux (push) Has been cancelled
Some checks failed
build and test / test-x86_64-linux (push) Has been cancelled
build and test / test-x86_64-osx (push) Has been cancelled
build and test / test-aarch64-osx (push) Has been cancelled
build and test / test-x86_64-win32 (push) Has been cancelled
build and test / test-i386-win32 (push) Has been cancelled
build and test / test-armv7-linux (push) Has been cancelled
build and test / test-aarch64-linux (push) Has been cancelled
build and test / test-riscv64-linux (push) Has been cancelled
When calculating the difference between two pointers (TOK_PDIV), the AArch64 and RISC-V64 backends used unsigned division instructions (udiv/divu). This patch moves TOK_PDIV to use signed division instructions (sdiv/div) for both backends, ensuring correct behavior as per the C standard.
This commit is contained in:
parent
5a370d8a6b
commit
11118be717
@ -1756,6 +1756,7 @@ static void arm64_gen_opil(int op, uint32_t l)
|
||||
o(0x4b000000 | l << 31 | x | a << 5 | b << 16); // sub
|
||||
break;
|
||||
case '/':
|
||||
case TOK_PDIV:
|
||||
o(0x1ac00c00 | l << 31 | x | a << 5 | b << 16); // sdiv
|
||||
break;
|
||||
case '^':
|
||||
@ -1798,7 +1799,6 @@ static void arm64_gen_opil(int op, uint32_t l)
|
||||
o(0x1ac02400 | l << 31 | x | a << 5 | b << 16); // lsr
|
||||
break;
|
||||
case TOK_UDIV:
|
||||
case TOK_PDIV:
|
||||
o(0x1ac00800 | l << 31 | x | a << 5 | b << 16); // udiv
|
||||
break;
|
||||
case TOK_UGE:
|
||||
|
||||
@ -1110,6 +1110,7 @@ static void gen_opil(int op, int ll)
|
||||
ER(0x33 | ll, 0, d, a, b, 1); // mul d, a, b
|
||||
break;
|
||||
case '/':
|
||||
case TOK_PDIV:
|
||||
ER(0x33 | ll, 4, d, a, b, 1); // div d, a, b
|
||||
break;
|
||||
case '&':
|
||||
@ -1127,7 +1128,6 @@ static void gen_opil(int op, int ll)
|
||||
case TOK_UMOD:
|
||||
ER(0x33 | ll, 7, d, a, b, 1); // remu d, a, b
|
||||
break;
|
||||
case TOK_PDIV:
|
||||
case TOK_UDIV:
|
||||
ER(0x33 | ll, 5, d, a, b, 1); // divu d, a, b
|
||||
break;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user