[PATCH] D15844: [ADT] Add an abstraction for embedding an integer within a pointer-like type.

Chandler Carruth via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 2 02:51:14 PST 2016


chandlerc created this revision.
chandlerc added a reviewer: rsmith.
chandlerc added a subscriber: llvm-commits.

This makes it easy and safe to use a set of flags as one elmenet of
a tagged union with pointers. There is quite a bit of code that has
historically done this by casting arbitrary integers to "pointers" and
assuming that this was safe and reliable. It is neither, and has started
to rear its head by triggering safety asserts in various abstractions
like PointerLikeTypeTraits when the integers chosen are invariably poor
choices for *some* platform and *some* situation. Not to mention the
(hopefully unlikely) prospect of one of these integers actually getting
allocated!

With this, it will be straightforward to build type safe abstractions
like this without being error prone. The abstraction itself is also
remarkably simple thanks to the implicit conversion.

http://reviews.llvm.org/D15844

Files:
  include/llvm/ADT/PointerEmbeddedInt.h
  unittests/ADT/CMakeLists.txt
  unittests/ADT/PointerEmbeddedIntTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15844.43845.patch
Type: text/x-patch
Size: 5677 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160102/e8952b3e/attachment.bin>


More information about the llvm-commits mailing list