qbicc icon indicating copy to clipboard operation
qbicc copied to clipboard

Nicer invalid pointer representation

Open dmlloyd opened this issue 2 years ago • 0 comments

When we construct Pointer instances in various ways (by adding a byte or element offset to a pointer, for example), the result is sometimes invalid (e.g., because we've speculatively computed a structure pointer index for a platform that does not have that member). We defer reporting an error until an invalid pointer is actually used in a memory operation. At present we use a null value to represent not only the null pointer value but also all invalid pointer values.

We could introduce a new RootPointer type specifically to represent an invalid pointer. The pointer type could include a nice error message explaining why the pointer is invalid. When a memory operation dereferences the pointer, it could then throw an exception with that error message.

In some Java VMs, invalid memory accesses trigger segmentation faults, which are captured by the JVM and are often transformed into a NullPointerException (even in some cases where the target pointer isn't null), so that is probably still an acceptable exception to throw for this case.

dmlloyd avatar Jun 30 '22 21:06 dmlloyd