Pointer diff should use signed size

This commit is contained in:
herman ten brugge 2024-02-09 08:35:32 +01:00
parent 76d605192d
commit a0ab99169e
2 changed files with 5 additions and 1 deletions

View file

@ -2983,6 +2983,7 @@ redo:
if (op != '-') if (op != '-')
tcc_error("cannot use pointers here"); tcc_error("cannot use pointers here");
vpush_type_size(pointed_type(&vtop[-1].type), &align); vpush_type_size(pointed_type(&vtop[-1].type), &align);
vtop->type.t &= ~VT_UNSIGNED;
vrott(3); vrott(3);
gen_opic(op); gen_opic(op);
vtop->type.t = VT_PTRDIFF_T; vtop->type.t = VT_PTRDIFF_T;

View file

@ -885,7 +885,7 @@ int tab4[10];
void expr_ptr_test() void expr_ptr_test()
{ {
int *p, *q; int arr[10], *p, *q;
int i = -1; int i = -1;
p = tab4; p = tab4;
@ -938,6 +938,9 @@ void expr_ptr_test()
i = ((long)p) >> 32; i = ((long)p) >> 32;
printf("largeptr: %p %d\n", p, i); printf("largeptr: %p %d\n", p, i);
#endif #endif
p = &arr[0];
q = p + 3;
printf ("%d\n", (int)((p - q) / 3));
} }
void expr_cmp_test() void expr_cmp_test()