diff options
author | herman ten brugge <hermantenbrugge@home.nl> | 2024-02-09 08:35:32 +0100 |
---|---|---|
committer | herman ten brugge <hermantenbrugge@home.nl> | 2024-02-09 08:35:32 +0100 |
commit | a0ab99169e35c733a033417f55c35b3c0d0f7194 (patch) | |
tree | 20fa5bdd989a326f6e4d5ebf1b345a6b31fb1994 | |
parent | 76d605192dae84c172722c3d73bf546a064b7e1c (diff) |
Pointer diff should use signed size
-rw-r--r-- | tccgen.c | 1 | ||||
-rw-r--r-- | tests/tcctest.c | 5 |
2 files changed, 5 insertions, 1 deletions
@@ -2983,6 +2983,7 @@ redo: if (op != '-') tcc_error("cannot use pointers here"); vpush_type_size(pointed_type(&vtop[-1].type), &align); + vtop->type.t &= ~VT_UNSIGNED; vrott(3); gen_opic(op); vtop->type.t = VT_PTRDIFF_T; diff --git a/tests/tcctest.c b/tests/tcctest.c index f03a940..c48f777 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -885,7 +885,7 @@ int tab4[10]; void expr_ptr_test() { - int *p, *q; + int arr[10], *p, *q; int i = -1; p = tab4; @@ -938,6 +938,9 @@ void expr_ptr_test() i = ((long)p) >> 32; printf("largeptr: %p %d\n", p, i); #endif + p = &arr[0]; + q = p + 3; + printf ("%d\n", (int)((p - q) / 3)); } void expr_cmp_test() |