Skip to content

LangRef: clarify semantics of dereferenceable #171777

@RalfJung

Description

@RalfJung

It is well-known, albeit unfortunately not documented in the LangRef, that dereferenceable on an argument means "this pointer must be dereferenceable for the entire duration of the function call".

But, what exactly does dereferenceable on the return type mean? This example by @nikic shows that apparently it does not just mean "dereferenceable here and now". But then what exactly is the scope for which that pointer is assumed to be dereferenceable? Is it the entire caller? That seems odd for two reasons:

  • How can a function promise that its caller will keep the pointer dereferenceable? It has no way of knowing that...
  • What about inlining? If this doesn't do anything special, it will extend the scope for which dereferenceable has to hold. To make that correct, basically dereferenceable would have to mean "dereferenceable for the entire rest of the program execution". Is that really the intent?

EDIT: Seems like indeed this persists through inlining.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions