Home

dereferenceable

Dereferenceable is a term used in computer science to describe a value, typically a pointer or reference, that can be safely dereferenced to access the object it designates. In formal terms, a pointer is dereferenceable for a given size if reading that many bytes starting from the pointer address yields defined behavior. The concept helps distinguish between mere pointer values and pointers guaranteed to provide valid memory access.

In LLVM and related compiler work, dereferenceable is an attribute attached to pointer values or parameters.

Dereferenceable is primarily a program-analysis and optimization aid rather than a language feature with runtime semantics

Limitations and caveats include that the guarantee is a contract the program must uphold; memory changes, deallocation,

A
pointer
marked
dereferenceable(n)
guarantees
that
at
least
n
bytes
of
memory
beginning
at
the
pointed-to
address
are
valid
to
read.
This
does
not
guarantee
that
the
pointer
remains
valid
after
the
current
scope
or
that
writes
to
that
region
are
allowed,
only
that
reads
of
that
region
are
safe.
If
a
dereference
would
access
memory
outside
that
region,
the
program
may
produce
undefined
behavior.
The
attribute
is
often
used
alongside
other
properties
like
nonnull
and
alignment
to
support
optimizations
and
safety
checks.
in
languages
such
as
C
or
C++.
It
is
used
to
improve
alias
analysis,
enable
vectorization,
and
provide
formal
proofs
of
safety
in
compiler
IR
and
static-analysis
tools.
A
typical
use
is
a
function
parameter
annotated
as
dereferenceable(4),
which
promises
that
reading
the
first
four
bytes
of
the
pointer
is
defined,
enabling
more
aggressive
optimizations.
or
lifetime
issues
can
violate
it.
It
is
not
a
substitute
for
proper
memory
management
but
a
tool
to
aid
analysis
and
optimization.
See
also
pointers,
memory
safety,
static
analysis,
and
LLVM
IR.