-
Notifications
You must be signed in to change notification settings - Fork 61
What are the exact semantics of pointer comparison? #239
Copy link
Copy link
Closed
Labels
A-provenanceTopic: Related to when which values have which provenance (but not which alias restrictions follow)Topic: Related to when which values have which provenance (but not which alias restrictions follow)A-ptr-eqTopic: pointer equalityTopic: pointer equalityC-open-questionCategory: An open question that we should revisitCategory: An open question that we should revisit
Metadata
Metadata
Assignees
Labels
A-provenanceTopic: Related to when which values have which provenance (but not which alias restrictions follow)Topic: Related to when which values have which provenance (but not which alias restrictions follow)A-ptr-eqTopic: pointer equalityTopic: pointer equalityC-open-questionCategory: An open question that we should revisitCategory: An open question that we should revisit
Type
Fields
Give feedbackNo fields configured for issues without a type.
Pointer comparison is complicated. However, for better or worse, Rust lets you safely compare any raw pointers, so we need to assign this some reasonable semantics. I wanted a place to centrally track all questions related to this, so here we go. (I never know whether to open such issues here in the UCG repo, or over in the rustc repo.)
There are two ways in which pointer comparison is "interesting": provenance, and objects without a guaranteed stable address.
Provenance
Does provenance affect whether pointers are equal? One major concern here is figuring out the semantics of pointer comparison in LLVM, and then likely we have no choice but to inherit that. Some data points:
malloccan always compare inequal even if they are physically equal. This directly contradicts Eli's statement above.I am trying to figure out if LLVM optimizations clearly indicate one or the other choice; so far that has been inconclusive.
Unstable objects
Functions, vtables, and consts do not have a unique stable address, also leading to interesting problems.
function address equality
vtable equality
const address equality