[ADT] Add a sum type abstraction for pointer-like types.
authorChandler Carruth <chandlerc@gmail.com>
Sun, 10 Jan 2016 08:48:23 +0000 (08:48 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Sun, 10 Jan 2016 08:48:23 +0000 (08:48 +0000)
commit560cdb12b5fa85b55842789e9fa30f5e4cb6dd21
tree34af1596e7ecc8c9339267b87b6cf02bb87f42ab
parent6d24e7dabe50eef669ccd0f3ccc814ac9ea3ac0a
[ADT] Add a sum type abstraction for pointer-like types.

This is a much more general and powerful form of PointerUnion. It
provides a reasonably complete sum type (from type theory) for
pointer-like types. It has several significant advantages over the
existing PointerUnion infrastructure:

1) It allows more than two pointer types to participate without awkward
   nesting structures.
2) It directly exposes the tag so that it is convenient to write
   switches over the possible members.
3) It can re-use the same type for multiple tag values, something that
   has been worked around by either abusing PointerIntPair or defining
   nonce types and doing unsafe pointer casting.
4) It supports customization of the PointerLikeTypeTraits used for
   specific member types. This means it could (in theory) be used even
   with types that are over-aligned on allocation to expose larger
   numbers of bits to the tag.

All in all, I think it is at least complimentary to the existing
infrastructure, and a strict improvement for some use cases.

Differential Revision: http://reviews.llvm.org/D15843

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257282 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/ADT/PointerSumType.h [new file with mode: 0644]
unittests/ADT/CMakeLists.txt
unittests/ADT/PointerSumTypeTest.cpp [new file with mode: 0644]