A discriminated union of two or more pointer types, with the discriminator in the low bits of the pointer.

Synopsis

Declared in <llvm/ADT/PointerUnion.h>

template<typename... PTs>
class PointerUnion
    : public pointer_union_detail::PointerUnionMembers<PointerUnion<PTs...>, 0, PTs...>

Description

This implementation is extremely efficient in space due to leveraging the low bits of the pointer, while exposing a natural and type‐safe API.

When all types have enough alignment for a fixed‐width tag, the tag is placed in the high end of the available low bits, leaving spare low bits for nesting in PointerIntPair or SmallPtrSet. When types have heterogeneous alignment, a variable‐length escape‐encoded tag is used; in that case, types must be listed in non‐decreasing NumLowBitsAvailable order.

Common use patterns would be something like this: PointerUnion<int*, float*> P; P = (int*)0; printf("%d %d", P.is<int*>(), P.is<float*>()); // prints "1 0" X = P.get<int*>(); // ok. Y = P.get<float*>(); // runtime assertion failure. Z = P.get<double*>(); // compile time failure. P = (float*)0; Y = P.get<float*>(); // ok. X = P.get<int*>(); // runtime assertion failure. PointerUnion<int*, int*> Q; // compile time failure.

Base Classes

Name

Description

pointer_union_detail::PointerUnionMembers<PointerUnion<PTs...>, 0, PTs...>

CRTP base that generates non‐template constructors and assignment operators for each type in the union. Non‐template constructors allow implicit conversions (derived‐to‐base, non‐const‐to‐const).

Member Functions

Name

Description

PointerUnion [constructor]

Constructors

operator=

Assignment from nullptr clears the union, resetting to the first type.

dyn_cast

Returns the current pointer if it is of the specified pointer type, otherwise returns null.

getAddrOfPtr1

If the union is set to the first pointer type get an address pointing to it.

getOpaqueValue

Return the packed pointer and tag bits as an opaque void pointer.

isNull

Test if the pointer held in the union is null, regardless of which type it is.

operator bool

Return true if the held pointer is non‐null.

Static Member Functions

Name

Description

getFromOpaqueValue

Reconstruct a PointerUnion from opaque void pointer VP.

Using Declarations

Friends

Name

Description

llvm::operator<

Order unions by their opaque bit patterns.

llvm::operator!=

Compare two unions for inequality of their opaque bit patterns.

llvm::operator==

Compare two unions for equality of their opaque bit patterns.

llvm::PointerLikeTypeTraits

A traits type that is used to handle pointer types and things that are just wrappers for pointers as a uniform entity.

llvm::CastInfo

This struct provides a method for customizing the way a cast is performed. It inherits from CastIsPossible, to support the case of declaring many CastIsPossible specializations without having to specialize the full CastInfo.

llvm::pointer_union_detail::PointerUnionMembers

CRTP base that generates non‐template constructors and assignment operators for each type in the union. Non‐template constructors allow implicit conversions (derived‐to‐base, non‐const‐to‐const).

Created with MrDocs