Open tstreiff opened 4 years ago
I think this is now resolved by your work with the pointer arithmatic (which I copied over). Could we create a test case for this?
The cast to int is no longer applied. This is much better. But having pointers larger than ints is troubling...
Having 64bit pointers, when indexing an array of very large objects, I do not expect to have 32bit overflow when indexing the array with ordinary ints.
I have just checked the C standard and the solution is there: the value "returned" by sizeof is not "int", it is size_t. size_t is large enough to be able to index any array of any size on the target system. This implies its size is similar to pointer size.
Briefly, size_t (or its signed friend ssize_t) is the integer type I computed in the (pointer - pointer) code. On x86_64 (pointer64, int32), pointerT + intvalue will lead to the evaluation of: pointer to T(64bit) + (intvalue(32bit) * sizeof(T)(64bit)) The multiplication must therefore be 64bit (because at least one operand is 64bit), and there is then no risk of hidden overflow.
I found this when compiling the "bsearch" function in stdlib.
generates the following IR (with int=32bit, ptr & long=64bit)
The most significant part of li is ignored. There should not be any i32 conversion involved in this case. "ptr + li" is equivalent to "(void)ptr + li sizeof(1)". Since li is long, the multiplication must be done with "li" size, ie 64bit.
This i32 conversion made me suspect another wrong case: